Copy a UD Record in a BPM

You can still use BufferCopy in E10, which also existed in ABL and I actually learned about if from one of your old ABL Codes.

// Example
BufferCopy.CopyExceptFor(QueryFromDBRecordRow, ttMyNewRow, "SysRowID","SysRevID","RevisionNum", "EffectiveDate", "RowMod");

// Change more stuff on ttMyNewRow
// Save

Example:

You might want to use CopyExceptFor and exclude KeyX and other fields like shown above – probably need to tweak this code a bit, but its a boilerplate.

Action UpdateUDRecord = (iResourceID) =>
{
  var UD02svc = Ice.Assemblies.ServiceRenderer.GetService(Db);
  var udRow = (from ud02 in Db.UD02 where ud02.Company == callContextClient.CurrentCompany && ud02.Key1 == "Runtime" && ud02.Key2 == iResourceID && ud02.CheckBox01 == true select ud02).FirstOrDefault();
  if (udRow != null)
    {
      UD02Tableset ds = UD02svc.GetByID(udRow.Key1,udRow.Key2,udRow.Key3,udRow.Key4,udRow.Key5);
      //Create the Before Image
      UD02Row OriginalRecord = (UD02Row)ds.UD02.NewRow();
      //Populate it
      BufferCopy.Copy(ds.UD02[0], OriginalRecord);
      //Add to the data set
      ds.UD02.Add(OriginalRecord);
 
 
      ds.UD02[0].Date02 = DateTime.Today;
      ds.UD02[0].Number02 = (decimal)((TimeSpan)(DateTime.Now - DateTime.Today)).TotalSeconds;
      ds.UD02[0].CheckBox01 = false;
      ds.UD02[0].RowMod = IceRow.ROWSTATE_UPDATED;
      UD02svc.Update(ref ds);
    }
};
1 Like