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.