Update UD field in standard directive

can anyone point on how can i update ud field in partplant from standard data directive? Do i need to write it directly in db or i can do it this way by adjusting some script. I can not figure out.

foreach(var line in poDs.PODetail)
{
  var svcpart = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.PartSvcContract>(this.Db); // Get service contract
  var  partDs = svcpart.GetByID(line.PartNum);
  var partDetails = partDs.Part.FirstOrDefault();
  var partPlantDetails = partDs.PartPlant.FirstOrDefault();
  if(partDetails.UserInteger1 > 0 && (bool)partPlantDetails["Inspection_c"] == true)
    {
       partDetails.UserInteger1 = partDetails.UserInteger1 - 1;
       if(partDetails.UserInteger1 < 1 && (bool)partPlantDetails["Inspection_c"] == true)
       {
          partPlantDetails["Inspection_c"] = false;
          partDetails.RowMod = "U";
          partPlantDetails.RowMod = "U";
       }
      else
      {
        partDetails.RowMod = "U";
      }
      svcpart.Update(ref partDs);
    }
  
  svcpart.Dispose();

}
    svc.Dispose(); // realease Service Contract

What is your business problem you’re trying to resolve? Before we throw C# in any BPMs - It’s always good to see if there is native functionality.

1 Like

we have custom bool in part table when we set it to true, userinteger1 in part table is set to 3 and bpm sets inspection required on PO line if PO created for that part. we need to set custom bool for related parts in part table to false when 3 PO orders are closed, this is totally custom process.

The BO can updated UD fields, they just don’t show up in the tableset. This is how you do it.

yourService.SetUDField("FieldName_c", "ValueToSet");

2 Likes

I haven’t read your code but just note, make sure you need a standard vs in-trans.

All of the data is not available in a standard, and it is already written.

1 Like

I’ve always seen this as SetUDField<System.[Data Type]> … is it not necessary to specify the type? or is that just for when the type may not be obvious to the compiler?

Necessary? No. But a good practice for sure as you will get a compiler warning if you have a type mismatch. Otherwise you don’t get it until runtime and it’s a lot harder to debug.

1 Like

I tried previously like this

foreach(var line in poDs.PODetail)
{
  var svcpart = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.PartSvcContract>(this.Db); // Get service contract
  var  partDs = svcpart.GetByID(line.PartNum);
  var partDetails = partDs.Part.FirstOrDefault();
  var partPlantDetails = partDs.PartPlant.FirstOrDefault();
  if(partDetails.UserInteger1 > 0 )
    {
       partDetails.UserInteger1 = partDetails.UserInteger1 - 1;
       if(partDetails.UserInteger1 < 1)
       {
          partPlantDetails.SetUDField<System.Boolean>("Inspection_c",false);
          partDetails.RowMod = "U";
          partPlantDetails.RowMod = "U";
       }
      else
      {
        partDetails.RowMod = "U";
      }
      svcpart.Update(ref partDs);
    }
  
  svcpart.Dispose();

}
    svc.Dispose(); // realease Service Contract

but strange everything works except ud field

I would have to test to be sure, but I don’t think you can update 2 rows at a time. Just update one row (the partPlantDetails) and try that. I suspect having 2 updated rows is what’s giving you the problem. When you need 2 different things updated, you probably need to do one row, update, then the other row, update again.

Are you following a trace? Make sure you follow the methods the same as the trace.

I think so, the only thing that I do not see in trace is U state of RowMod. It is empty, only UD field value changes when I do this manualy. Do I need to skip RowMod?

In a standard directive, the update has already happened, so you will not.
Also, as Brandon said, you will likely not have access to all the rows.

Yes, that is true, i can not update 2 rows at once