Subroutines in BPMs?

Is it possible to write subroutines in BPMs without an external DLL?
I’ve got some custom code that runs through some date checks and there’s a fragment of code that checks the dates against our production calendar and weekends that gets repeated a lot. It would be nice to put that in a subroutine and then be able to just call it instead of repeating it in my code.

3 Likes

by subroutines do you mean functions? I’m interpreting it as that, you can’t define functions but you can use Actions (plenty out on google regarding C# Actions) which then can be called like a function. define that at the top like the example below.

Action AddMiscCode = (miscCode, packNum) =>
{
using(var custShipSvc = Ice.Assemblies.ServiceRenderer.GetService(Db))
{
CustShipTableset csts = new CustShipTableset();
csts = custShipSvc.GetByID(packNum);
custShipSvc.GetNewShipMisc(ref csts, packNum, 0, 0);
custShipSvc.GetShipMiscDefaults(ref csts, miscCode);
var x = csts.ShipMisc.Where(r => r.Added()).FirstOrDefault();
x.DocMiscAmt = 999999.99M;
x.DspMiscAmt = 999999.99M;
x.MiscAmt = 999999.99M;
custShipSvc.Update(ref csts);
}
};

2 Likes

While Googling Actions, I came across Func. That appears to be what I need as I need a value returned and it looks like Actions are void delegates. Thanks Rob!

3 Likes

We created Scalar-valued functions within the sql DB. runs like a charm.
for example I can add a calculated field representing the previous date of today, we call our function: ply.PrevWeekDay(Constants.Today ,1, ‘5J-24H’)

I do not understand how the Epicor dev team has slipped on this essential feature…( is this implemented into 10.2.200 ?? )
Meaning the date check in a BPM against Next x days, should have another choice…Next Business days provided the Calendar value and days difference needed. When a customer needs a 5 business days delivery time, we need to take into account week ends, and holidays !!! We should not have to do this up in our head! That is way the Calendar exists for production time no ?

So if you create your function into the DB you will be able to access in the BAQ no need of external DLL…

Pierre

I have used Functions many times in the Product configurator… Here is an example where I created a function called “GetReplacementpart” to reduce and simplify multiple calls to it within the switch statement:

//Following, you pass a string, and return a string.
Func<string, string> GetReplacementPart = (MyPart) =>
PCLookUp.DataLookup(“CFG-GAL25”, Inputs.Pg01_cmb_Gurtbreite.Value, MyPart) ?? MyPart;

switch (Context.Entity)
{
case “JobMtl”:
JobMtl.PartNum = GetReplacementPart(JobMtl.PartNum);
break;
case “QuoteMtl”:
QuoteMtl.PartNum = GetReplacementPart(QuoteMtl.PartNum);
break;
case “ECOMtl”:
ECOMtl.MtlPartNum = GetReplacementPart(ECOMtl.MtlPartNum);
break;
}

4 Likes

Thanks Tim, that’s exactly what I ended up doing!

1 Like

I’m not sure I understand… at the top of what? How do you share this action between multiple BPMs to avoid having to repeat them same code in a lot of places?

It’s not across multiple BPMs, it’s just in the same code block so you don’t have to have multiple copies in the same code block.

Not just that, it is helpful to break down a large function into smaller blocks - not as good as proper subroutines, but still a useful improvement. Later Epicor you should investigate using the new Functions feature as these can be called from multiple BPMs (amongst other good things like the function is automatically available via Epicor’s REST API).

2 Likes

C# 7 has local functions, but Epicor apparently doesn’t support this language version yet. (At least not on 10.2.100…)

Is there a possibility to set theses actions somewhere in the configurator code so that is could be used in different places?

Edit:
I know there are UD Methods for each configurator. But I’d like to centralize the methods somewhere!

No. But the hope is that eventually the Product Configurator will be able to call Epicor Functions which appeared in 10.2.500. Pretty sure it’s on the roadmap but no timeline that I have heard.