I have a BPM on OrderHed where I want to set the UD field OrderDtl_UD.LineHold_c to yes if Customer.CreditHold is true and OrderHed.OrderHeld is true. The code is bombing when I try to set LineHold_c to true. Do I need to call the UD field a different way than what I currently am?
var y = ttOrderHed.FirstOrDefault(r => r.RowMod == "A" || r.RowMod == "U");
if (y != null && y.PONum != null)
{
var b = Db.Customer.FirstOrDefault(s => s.Company == y.Company && s.CustNum == y.CustNum);
if (b.CreditHold == true || y.OrderHeld == true)
{
var c = Db.OrderDtl.FirstOrDefault(s => s.Company == y.Company && s.OrderNum == y.OrderNum);
c.LineHold_c = true;
this.PublishInfoMessage("CreditHold = " + b.CreditHold + ", OrderHeld = " + y.OrderHeld, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual,"","");
}
}
So I tried to put in a message to see what/if LineHold_c was getting any data and it also gives me an error message which is what made me think I was calling LineHold_c wrong.
Maybe because I’ve run into it in several different environments, try something simple like setting the value to 1 instead of true. I have found MANY places where code just seems to like 1 and 0 instead of true and false, and since they can be used inter-changeably in most places, it’s worth trying to switch it when a weird error is showing up.
Look at your event viewer for details on the error (search by correlation id if needed).
I suspect one of these:
UD field was NOT regen\recycled
Does autocomplete work for the field? If not, you’ll need to access it via cs c.UDField<bool>("LineHold_c") to get and c.SetUDField<bool>("LineHold_c",true\false) to set
You are using first or default, but not checking for null after setting c, if(c==null) return;
I changed the code, and it works now. But it doesn’t show the checkbox as checked unless you refresh the page. Is there a way to automatically refresh the page?
I’m doing this in data directive erp.OrderHed.Update In-Transaction
var c = Db.OrderDtl.FirstOrDefault(s => s.Company == y.Company && s.OrderNum == y.OrderNum);
if (c == null)
return;
c.UDField<bool>("LineHold_c");
if (y.CreditOverride == true)
{
c.SetUDField<bool>("LineHold_c", false);
}
else
{
c.SetUDField<bool>("LineHold_c", true);
}