Function inside Execute Custom Code using BPM

Hi,

Could you please suggest how to write a function inside Execute Custom Code using BPM?

For ex…

Public void UpdateOrder()
{
//----- Your Logic -----//
}

lookup how to write “Func” and “Action” statements in C#.

//simple function:
Func<decimal,decimal> DoublePrice = (OldPrice) => OldPrice * 2;

//Multi-line function:
Func<decimal,decimal> ExtendPrice = (OldPrice) =>
	{
	decimal myMargin = 3;
	return OldPrice * myMargin;
	};

//examples of calling the above functions:
Inputs.UnitPrice_Dec.Value = DoublePrice(Inputs.UnitPrice_Dec.Value);
Inputs.UnitPrice_Dec.Value = ExtendPrice(Inputs.UnitPrice_Dec.Value);
2 Likes

Action: https://www.dotnetperls.com/action
Func: C# Func Type Examples - Dot Net Perls

2 Likes

by the way, these can be used in BPMs, as well as Epicor Functions, and Product Configurator code.

But in all these places listed above, you are NOT allowed to create your own methods. (Except configurator which has “User Defined Methods” which are a special method that has wrappers around them)
ALSO, Epicor Functions are where you can create your own Methods that are universal and full citizens of the Epicor software on your system.

But if you do this in Configurator code (not the UD Config Method), it would have limited scope to where the code was placed, no?

Like if I made a Func<> in the OnLeave event of a control, that Func could only be called within that event of that specific control. Correct?

correct… so in the product configurator, I would use a UDMethod instead of a function… but I sometimes put functions inside a complicated UDMethod to reduce code. A function can reduce code simply by the fact that you can put redundant code in the function. Of course, if you want that function in more than one UDMethod, it might be better to create a second UDMethod that is called from the first.

2 Likes