Modify DMRActn Record

I’m trying to implement a process flow that involves a UD Field that I’ve added to the DMRActn table. When a DMR Reject is saved, it puts a value in the UD Field. Later when a matching PO line is received, I need to change the value from true to false. Sounds simple. In my BPM that handles the fact that the PO Line is received, it correctly finds the matching DMRActn record, sets the field to false and “Saves” it (verified through PublishInfoMessage). Sadly, the value in the table is never changed. Either, I’m not saving it correctly, or you can’t actually update a DMRActn record once it exists. I’ve believe that I’ve tried many combinations of PreUpdate, Update and CustomUpdate (individually and in combinations). Thanks for any help that can be provided. Here’s my current code:

var row = (from r in Db.DMRActn where r.SysRowID == @DMRActnGUID select r).FirstOrDefault();
if (row == null)
{
return;
}

using (var dmrSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.DMRProcessingSvcContract>(Db))
{
Erp.Tablesets.DMRProcessingTableset dmrTS = new Erp.Tablesets.DMRProcessingTableset();
dmrTS = dmrSvc.GetByID(row.DMRNum);

var dmrActnRow = (from r in dmrTS.DMRActn where r.SysRowID == @DMRActnGUID select r).FirstOrDefault();
if (dmrActnRow != null)
{

   dmrActnRow["OpenPO_c"] = @WaitingForPOLine;
   
    bool results;
   dmrSvc.PreUpdate(ref dmrTS, out results);
         
   string strResults = "";
   dmrSvc.CustomUpdate(ref dmrTS, out strResults);
         
   dmrSvc.Update(ref dmrTS);
 }

}

You may need to set the RowMod before the update. Also, if you are using a UD field and code, you could potentially just update the field directly (without a Business Object).
dmrActnRow["RowMod"] = "U":

When I setting Row Mod to “U” the data still doesn’t change, but now either Update or CustomUpdate causes the BPM to crash with a NullReferenceException whether I run them before or after the PreUpdate.

I don’t have any idea how to update the field directly (without a business object). The BPM that is running is a Data Directive on POLine (InTransaction) and it has no direct access (that I can find) for he DMRActn table.

I’m working my way (blindly) through this. Thanks to everyone who has posted anything LIKE this, because I’ve copied your code.

Since I don’t know all of the filters you are using from the snippet you’ve sent, I am making guesses, but this should help:

using (var txScope = IceContext.CreateDefaultTransactionScope())
{
	foreach (var tt in ttPODetail.Where(tt => tt.Updated() && !tt.OpenLine /* add other filters here */))
	{
		
		foreach (var D in Db.DMRActn.Where(D => D.Company == tt.Company && D.OpenPO_c == tt.PONum))
		{
			D.POReceived_c = true;
		}
		
  Db.Validate();
  txScope.Complete();
}

I put in your code with some mods to make it do what I want. By the time I get to the custom code, I have filtered to wanting to set the field on the DMRActn row that is associated with the saved PODetail row. The code represents the entire contents of the custom code block. I’ve updated the code to basically what you had (see below) and plopped in an InfoMessage to make sure that the variable is being set. Sadly, the value is still not actually being updated in the database. I assume that the txScope.Complete is supposed to be committing the changes, but perhaps there still needs to be some sort of “save”?

using (var txScope = IceContext.CreateDefaultTransactionScope())
{
foreach (var tt in ttPODetail.Where(tt => tt.Updated()))
{

foreach (var D in Db.DMRActn.Where(D => D.Company == tt.Company && D.SysRowID == tt.DMR_ID_c))
{
string body = "CustomPODetail Code. DMR# = " + D.DMRNum;
this.PublishInfoMessage(body, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, “FirstVar”,“SecondVar”);
D.OpenPO_c = true;
}
}
Db.Validate();
txScope.Complete();
}

So you see the message, but it still does not update?
Do you have a conflicting Data Directive on DMRActn?

I have a Data Directive on the DMRActn record, but it doesn’t conflict (it’s acting on the DMRHead record) and it’s not triggering because the record is never changed. I have a bunch of show messages in these BPMs while I an trying to debug them and make sure they trigger appropriately. The only thing that’s odd (to me) is that the info boxes from the code show up before the show messages in the rest of the BPM, even though the custom code is the last thing in the chain.

The DMR stuff in Epicor is really different than (most of) the rest of the tables. I’m going to try some test C# code in a standalone application I have to see if it can save the record through the DMRProcessing adaptor in a place where I can actually look at the results of my actions.

The code that I wrote in the standalone code DID cause the field to change in the database, so this must be doable. C# code below. I don’t know how to translate this into things the BPM understands. I’m out until Monday, so don’t look for a response to any response you provide before then. Thanks!
public void DMRSetRejectRecordStatus(int dmrID, Guid DMRActnGuid, bool blnWaitingForPO)
{
DMRAdapter.ClearData();

        DMRAdapter.GetByID(dmrID);

        DMRProcessingDataSet ds = DMRAdapter.DMRProcessingData;
        for ( int i = 0; i < ds.Tables["DMRActn"].Rows.Count; i++)
        {
            DataRow dr = ds.Tables["DMRActn"].Rows[i];
            if (dr["SysRowID"].ToString() == DMRActnGuid.ToString())
            {
                dr["OpenPO_c"] = blnWaitingForPO;
            }
        }

        bool reqUserInput;
        DMRAdapter.PreUpdate(out reqUserInput);

        //DMRAdapter.CustomUpdate(ds, out msg);
        string msg;
        DMRAdapter.Update(out msg); // trace shows a call to CustomUpdate!!
    }

Your BPM code looked good to me. For the future, could you format your code like the reply box describes?
image

Here is your code formatted (below). Can you verify the GUID exists in the DMR_ID_c field?

using (var txScope = IceContext.CreateDefaultTransactionScope())
{
   foreach (var tt in ttPODetail.Where(tt => tt.Updated()))
   {
      foreach (var D in Db.DMRActn.Where(D => D.Company == tt.Company && D.SysRowID == tt.DMR_ID_c))
      {
         string body = "CustomPODetail Code. DMR# = " + D.DMRNum;
         this.PublishInfoMessage(body, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
         D.OpenPO_c = true;
      }
   }
   Db.Validate();
   txScope.Complete();
}

Thank you for your help. Your code worked all along - I missed that I was always setting the value to true :frowning: . Also, thanks for telling me how to do the formatting. I was a little frantic and I didn’t understand the instructions, so I ignored them. I am really appreciative of the quick help I got in this forum.