It really depends on which one we are talking about. In this case, what I am trying to make sure is that a job is not released without a final operation being marked on the main assembly.
In effect, what I am doing is checking if JobHead.Release has been changed to true and if so, with the related JobAsmbl table with AsmblSeq = 0 that FinalOpr <> 0.
I could check if ds.JobHead.Released = true within the method, then send the JobNum into the function and in the function, check if the related JobAsmbl table with a sequence of zero has a finalopr <> 0 and if not, throw an exception then. But honestly, at that point, itās pretty much pointless to send it to a function. If I were checking all of it within the function, it would only be beneficial if I were to use it in a couple of places. But if Iām doing the first check in the method directive then there really isnāt much advantage to making the second check in the function as Iām still going to have to make the first check in every method where I want to use it.
If I understand correctly, making a function call from a BPM has pretty low overhead, since it a local call.
If youāre going to have to re-write code several times, it is advantageous to make it a single function call in each location - especially considering the possibility of having to re-write that same code in the future: just changing in one place is better than keeping the same code in sync across several BPMs/data directives. Even if it is only a few lines/widgets.
Two-cents-worth from a wannabe software engineerā¦
Iām a huge fan of functions. I use them in my programming outside of Epicor.
However, in Epicor, if I canāt send in the dataset that is currently being updated and I have to perform checks against the dataset that is being updated outside of the function, it really limits how much that function is helping me. In this case, Iām doing a check prior to the function, then would be sending it to a function that would consist of a single conditional followed by a raise exception.
So Iād be adding an object in my BPM to call the Function. Creating a function library, then creating a function within that library, then putting two things within the function, then going everywhere I want to use this and do the same thing. For something more intense, this might be worth it. For something this simplistic, if I canāt do it all in the function, thereās no point in doing a tiny portion within a function and calling the function. In essence, Iām basically doing more work to perform the same task which is the opposite of the reason to use the function in the first place.
CallService<Erp.Contracts.JobEntrySvcContract>(je =>
{
outJETS = je.GetByID("266745-1-1");
outJETS.JobHead.FirstOrDefault().CommentText = "I am a man of constant sorrow.";
});
Thanks for this. Although I wonāt be using a function for this issue in particular, I am excited about the possibility of using them for other things. Thanks for pointing me in the right direction to start as Iāll be taking this code and modifying it to try out a couple things and hopefully start leaning into using functions where possible.