Copy NC Comment to DMR Code help

,

Hi all,
I am trying to copy the NonConf comments into the DMR Comments along with the Failed Comments (that are already pulled over). I have added an in-transaction Data Directive on the DMRHead table. Check Syntax button says the code is OK.

When I try to create a DMR from an NC I get the error below:

BPM runtime caught an unexpected exception of 'NullReferenceException' type.
See more info in the Inner Exception section of Exception Details.

Exception caught in: Epicor.ServiceModel

Error Detail 
============
Description:  BPM runtime caught an unexpected exception of 'NullReferenceException' type.
See more info in the Inner Exception section of Exception Details.
Program:  ERP.DMRHead.Triggers.dll
Method:  A002_CustomCodeAction
Original Exception Type:  NullReferenceException
Server Trace Stack:     at Epicor.Customization.Bpm.DB4442F3283D2F42D0AF831A396B99FA38.InTranDirective_AddComment_6360BE3736CF474C8A18979070D8F953.A002_CustomCodeAction()
   at Epicor.Customization.Bpm.DB4442F3283D2F42D0AF831A396B99FA38.InTranDirective_AddComment_6360BE3736CF474C8A18979070D8F953.ExecuteCore()
   at Epicor.Customization.Bpm.DirectiveBase`3.Execute(TParam parameters) in C:\_Releases\ICE\ICE3.2.200.40\Source\Server\Internal\Lib\Epicor.Customization.Bpm\DirectiveBase.Generic.cs:line 147

Client Stack Trace 
==================
   at Epicor.ServiceModel.Channels.ImplBase`1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets)
   at Erp.Proxy.BO.InspProcessingImpl.InspectInventory(String& legalNumberMessage, Int32& iDMRNum, InspProcessingDataSet ds)
   at Erp.Adapters.InspProcessingAdapter.InspectInventory(String& legalNumberMessage, Int32& iDMRNum, InspProcessingDataSet ds)
   at Erp.UI.App.InspectionProcessingEntry.Transaction.InspectInventory(Int32& dmrNum)
   at Erp.UI.App.InspectionProcessingEntry.Transaction.Update(String key)
   at Erp.UI.App.InspectionProcessingEntry.Transaction.onUpdate(String key)
   at Erp.UI.App.InspectionProcessingEntry.InspectionProcessingEntryForm.OnClickSave()
   at Ice.Lib.Framework.EpiBaseForm.handleToolClickInternal(String tKey, ToolClickEventArgs ea)
   at Ice.Lib.Framework.EpiBaseForm.handleToolClick(String tKey, ToolClickEventArgs ea)

Inner Exception 
===============
Object reference not set to an instance of an object.

My code:

//get NC table
Erp.Tables.NonConf NCTable;

//get DMRHead table
var NewDMR = ttDMRHead.FirstOrDefault();

//get DMR number
var DMRnum = NewDMR.DMRNum;

//link DMR and NC
NCTable = (from NCTable_row in Db.NonConf
           where NCTable_row.Company == Session.CompanyID
           && NCTable_row.DMRNum == DMRnum
           select NCTable_row).FirstOrDefault();
           
        
//set DMR Head Comment
NewDMR.CommentText = NCTable.CommentText +' '+ NCTable.FldCommentText;

You’re almost there. Just get the updated DMR header instead of just the first one and add some validations.

// get dmr header
var dh = (from dhrow in ttDMRHead where (dhrow.RowMod=="A" || dhrow.RowMod=="U") select dhrow).FirstOrDefault();
if (dh!=null)
{
  // get nonc
  var nc = (from ncrow in Db.NonConf where (ncrow.Company==dh.Company && ncrow.DMRNum==dh.DMRNum) select ncrow).FirstOrDefault();
  if (nc!=null)
  {
    // update dmr comments
    dh.CommentText = nc.CommentText +' '+ nc.FldCommentText;
  }

}
2 Likes