Null Exception when Update Petty Cash Document using BPM

Hi, I want to update the UD Field that I created for the PCash Doc table. But I don’t know why I always got this Null Exception. My Code is not that complex and I only updating one field and it is hardcoded. So I must not get the null exception because I already have the condition to throw a custom message when the PCashDoc is null after GetById is called.

using(var pcashDocSvc = Ice.Assemblies.ServiceRenderer.GetService<PCashEntrySvcContract>(Db))
          int referenceNum = Convert.ToInt32(pcd.Character01);
          PCashEntryTableset pcashdoc = pcashDocSvc.GetByID(ud105.Character01, referenceNum );
          bool preUpdateComplete = false;
          if(!(pcashdoc.PCashDoc.Count > 0 ) || pcashdoc == null || pcashdoc.PCashDoc[0] == null)
             throw new Exception("Petty Cash Doc tidak ditemukan " + ud105.Character01 + " " + pcd.Character01);
          //pcashDocSvc.PreUpdate(ref pcashdoc, out preUpdateComplete);
          pcashdoc.PCashDoc[0].RowMod = "U";
          //pcashDocSvc.OnChangePCashDocApplyDate(DateTime.Now.Date, ref pcashdoc);
          //pcashdoc.PCashDoc[0].ApplyDate = DateTime.Now.Date;
          pcashdoc.PCashDoc[0].SetUDField("Status_c", "In Approval");
          pcashDocSvc.Update(ref pcashdoc);

The error only shows when I set the row mode to Update when I comment this line pcashdoc.PCashDoc[0].RowMod = “U” I don’t get any error but of course, my row is not updated;

this is the error
Object reference not set to an instance of an object.

Your reasoning seems correct. If pcashdoc.PCashDoc[0] were null, it wouldn’t just fail to update when you comment out setting RowMod. Your own exception would be thrown. Plus, calling SetUDField would also throw NRE. So it must be something required by Update that’s missing from the dataset.

This kind of thing can be really hard to troubleshoot. If you’re lucky, the stack trace might provide a hint. It’s under the “details” button on the error dialog.

Sadly the stack trace doesn’t give any information, I wonder what makes this happen. Yes, maybe there is some field that needs to be filled when the Row Mod is Updated.

Were you able to find an answer to this? I am experiencing setting an ud field on Case Entry and getting the Null Exception error. Might be similar.