Addressing a UD table in a BPM

I have copied this code from an Epicor author, and I am sure would work well, except that….

I defined a couple UD field for the OrderHed table and continued, as in the original example that came from Epicor, to refer to it as ttOrderHed. It was not overly happy and said that the the UD fields (xxx_c fields) were not recognised.

So I tried to use ttOrderHed_UD as the reference to the view… but checking the synthax, it said the name did not exist in the current context.
So I tried Db.OrderHed in the odd chance it’d be the view name, and it passed the syntax check. But at run time there is an error.

If anyone has an idea, that would be lovely!

Here is the code:

/* Greatly inspired from code Written by Tim Shoemaker tshoemaker@epicor.com 4/22/2015 Epicor Software Corp*/

Ice.Tables.UDCodes UDCodes = null;

/Here we will get the current new customer record that was just created… only if it has “Auto” in the WardsOrder_c id field./
foreach (var MyOrder in (from ThisOrder in Db.OrderHed
where ThisOrder.WardsOrder_c == “Auto”
select ThisOrder))

{
/If we are here, this must be a newly added Order and the WardsOrder_c ID was “Auto”…
This next section reads the “BU” record from UDCode table to retrieve the next number from the UDCodes.CodeDesc field…
it assigns that to the WardsOrder_c field, and then increments and saves the next customer number for later use
/
using (var txScope = IceContext.CreateDefaultTransactionScope())

{
foreach(var MYUDCodes in (from ThisUDCodes in Db.UDCodes.With(LockHint.UpdLock) where
    ThisUDCodes.Company == Session.CompanyID &&
    ThisUDCodes.CodeTypeID == "BU" &&
    ThisUDCodes.CodeID == MyOrder.BusinessUnit_c
select ThisUDCodes))
    {
    /*If we are here, we have found the next WardsOrder number in the UDCodes table... lets use it*/
    int NextWardsOrder;
    int.TryParse(MYUDCodes.CodeDesc,out NextWardsOrder); //retrieves the next # from the Desc field into NextCustNum
    MyOrder.WardsOrder_c = MyOrder.BusinessUnit_c + NextWardsOrder.ToString("0000000"); //sets the WardsOrder
    NextWardsOrder += 1; //Increment the next number
    MYUDCodes.CodeDesc = NextWardsOrder.ToString(); //save the new next id in UDCodes
    }
Db.Validate();
txScope.Complete();
}

}
/end of BPM/

You can’t use the “dot” syntax when accessing UD fields. You have to use the [ ] indexing:

foreach (var MyOrder in (from ThisOrder in Db.OrderHed where ThisOrder["WardsOrder_c"] == "Auto" select ThisOrder))

and

MyOrder["WardsOrder_c"] = MyOrder["BusinessUnit_c"].ToString() + NextWardsOrder.ToString("0000000");

There are a few topics on this scattered around the forum.

1 Like

Waoh… I would never have guessed in a million years… Had to go back to ttOrderHed[“xxx”] instead of Db.OrderHed[“xxx”] and it worked like a charm….

Thank yo so much Tyler! This had been eluding me for so long…:grinning: