Trouble updating PartLot inside BPM

I am using the LotSelectUpdate service inside a BPM. I am setting the PartLot.ExpirationDate field inside the code, but it’s not actually setting it. I am getting though the entire code as shown by my messages, but the record doesn’t update.

/*Look Up Part Lot Rec and Update the Expiration Date from the Date06 field*/

foreach(var rec in ttUD100.Where(tt=>tt.Updated()))
  {
    if(rec.ShortChar05 == "CTS")
    {
    /*LotSelectUpdate Svc*/   
    /*Attempt to find Part Lot rec*/
      using(var svc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.LotSelectUpdateSvcContract>())
      {
        /*create PartNum, LotNum as strings, just to be safe*/
        string partNum = rec.Key2.ToString();
        string lotNum = rec.Key1.ToString();
        
        var ds = svc.GetByID(partNum, lotNum);
        if(ds!=null)
          {
            DateTime uDate = Convert.ToDateTime(rec.Date06); //Supplier Expiration Date
            DateTime plDate = Convert.ToDateTime(ds.PartLot[0].ExpirationDate);
            string msg2 = uDate.ToString() + " " + plDate.ToString();
        this.PublishInfoMessage(msg2, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
            /*Attempt to match up corresponding UD100 rec, if true update PartLot.ExpirationDate from UD100.Date06*/
            //if(DateTime.Compare(uDate, plDate)!=0)
              //{
                ds.PartLot[0].ExpirationDate = Convert.ToDateTime(DateTime.Parse("2018-09-01"));
                /*Update*/
                svc.Update(ref ds);
                
                string msg3 = "Made it past Update";
        this.PublishInfoMessage(msg3, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
             // }
          }
      }
    }
  }

Before:
image

During:


After:
image

As you can see, it processed all the code but didn’t update the field. I am able to update the field using the BL Tester and the Update method and it works fine.

What’s going on?

Some business objects require you to pass in 2 rows an unchanged row and a modified row. Try this, after you get your part lot record create a new one

//Create a new Part lot Row
var newPL = (PartLotRow)ds.PartLot.NewRow();
//use buffer Copy to clone the first row
BufferCopy.Copy(ds.PartLot[0], newPL);
then modify the new one
newPL.ExpirationDate = whatever....
newPL.RowMod="U";

//then add the new record to the tableset
ds.PartLot.Add(newPL);

//then call update
1 Like

Perfect, thanks Jose! I was banging my head against the wall on this one.

that was quick… It worked?

It sure did

1 Like

Awesome. technically speaking you should do that with EVERY BO… most people don’t… and it can lead to some pretty gnarly business logic bugs.

Good to know, it does seem a bit safer to use a buffer copy. Another tool in my toolbelt! :slight_smile:

Epicor uses that to check “what has changed” like in BPMS when you say from X changed from Z to Y… that’s what they use. If that one is not provided those things will fail.