Delete UserComp via BO

Hi all, I am frustrated and desperate. I have spent nearly my entire day trying to do one simple thing with no luck.

I am trying to remove plants from a user ala UserComp. You cannot save a UserComp with an empty plantlist - makes sense to me.

I have tried umpteen different flavors of UserFile.Update() to delete this record. In most cases, I get no errors, but also the record is not deleted. I have tried with and without a before image record.

//thisUserComp rec is my current record
   uf.AddUserCompany(user, ref ufts);
   var newRec = ufts.UserComp.First(f => f.RowMod == "A");   
   BufferCopy.Copy(thisUserCompRec,  newRec);   
   //new row will delete
   newRec.RowMod = "D";
  uf.Update(ref ufts);

No errors, no action.

Strangely tracing isnt helpful, even with a full trace and responses it shows me only the RESULT (not the data going into the call).

Even UpdateExt says things are good, the rogue record still in the Db begs to differ.

@Chris_Conn It looks like you can only change the plant list in UserComp or if you want to delete you have to go up to UserFile and delete that record which also deletes UserComp

<paramDataSetChanges>
    <paramDataSet name="ds" useDataSetNbr="0">
      <deletedRow tableName="UserFile" rowState="Deleted" rowNum="0" />
      <deletedRow tableName="UserComp" rowState="Deleted" rowNum="0" />
    </paramDataSet>
  </paramDataSetChanges>

But when I tried to to a ubaq and see the code that it generated there are a bunch of issues, so I think this is a no fly zone.

Ever since moving to E11 I have been having similar issues trying to delete things even on UD tables.

Found a nice snippet from Jose at one point, don’t remember the post or I’d tag it. This is what I got working though using a SvcContract, seems to be about the only reliable one I’ve been using lately.

Ice.Contracts.UD01SvcContract UD01Svc = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD01SvcContract>(Db);

var list = Db.UD01.Where(I => I.Key1 == "YourFilter").ToList();

if (list != null && list.Count > 0)
  foreach (var row in list)
  {
      UD01Tableset tableset = UD01Svc.GetByID(row.Key1, row.Key2, row.Key3, row.Key4, row.Key5);
      
      tableset.UD01[0].RowMod = "D";
      
      UD01Svc.Update(ref tableset);
  }

Maybe a similar approach will work - letting the Db context close the table so it’s free to update again (or at least my guess as to what’s happening).

Here’s to remove a Plant (You need to use BeforeImage for this BO)

Input: UserId, PlantId
Output: Success, Message

Service: Ice.BO.UserFile

this.CallService<Ice.Contracts.UserFileSvcContract>(usr => {
  var usrData = usr.GetByID(this.UserID);
  var compRow = usrData.UserComp.Where(r=>r.Company==this.Session.CompanyID).FirstOrDefault();
  var newCompRow = new UserCompRow();
  var ogCompRow = new UserCompRow();
   Epicor.Data.BufferCopy.Copy(compRow,newCompRow);
   Epicor.Data.BufferCopy.Copy(compRow,ogCompRow);
   usrData.UserFile.Clear();
   usrData.UserComp.Clear();
   usrData.UserCompExt.Clear();
   var plantArray=newCompRow.PlantList.Split("~").ToList();
   plantArray.RemoveAll(s=>s==this.PlantToRemove);
   newCompRow.PlantList=String.Join('~',plantArray);
   newCompRow.RowMod="U";
   usrData.UserComp.Add(newCompRow);
    usrData.UserComp.Add(ogCompRow);
    usr.Update(ref usrData);
    this.Success=true;
     usrData = usr.GetByID(this.UserID);
     compRow = usrData.UserComp.Where(r=>r.Company==this.Session.CompanyID).FirstOrDefault();
    this.Message = compRow.PlantList;
});

Here’s to Remove a Company

this.CallService<Ice.Contracts.UserFileSvcContract>(usr => {
  var usrData = usr.GetByID(this.UserID);
  var compRow = usrData.UserComp.Where(r=>r.Company==this.CompanyToRemove).FirstOrDefault();
  var newCompRow = new UserCompRow();
  var ogCompRow = new UserCompRow();
   Epicor.Data.BufferCopy.Copy(compRow,newCompRow);
   Epicor.Data.BufferCopy.Copy(compRow,ogCompRow);
   usrData.UserFile.Clear();
   usrData.UserComp.Clear();
   usrData.UserCompExt.Clear();
   
   newCompRow.RowMod="D";
   usrData.UserComp.Add(newCompRow);
    usrData.UserComp.Add(ogCompRow);
    usr.Update(ref usrData);
    this.Success=true;
     usrData = usr.GetByID(this.UserID);
});

Here’s the EFX:
UACT.efxb (3.7 KB)

You got that comprehensive list for us typed up yet?

Nope when in doubt before image