BPM setting a UD checkbox to yes help

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,"","");
  
   }
 
}

What do you mean it’s bombing?

Also, you didn’t save it.

You didn’t know what I meant by bombing. Sorry, way too vague. :slight_smile:

It saves when I save the data directive but when I try to test it from the sales order entry page I get a generic error message.

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.

image

What do you mean when you say I didn’t save it. What do I need to do?

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:

  1. UD field was NOT regen\recycled
  2. 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
  3. You are using first or default, but not checking for null after setting c, if(c==null) return;
1 Like

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);
        }

Not from the bpm. It’s on the server.

You might could find an apporpriate client side event to check for a condition, and do it, but that’s always iffy.