Calling Functions from another Function

I need to call a Function from a different Function Library from within some either custom code in my function or from the Call Function widget.
I am iterating over a collection and will be calling the function with the current iteration of the collection (basically cycling down a list of part numbers and passing that part into a function).

I am not seeing an intuitive way to do this with the widget. I could probably try it with building a rest client in the custom code widget, but that’s messy. Is there a better way to do approach?

Try with custom code calling a Function within a Function. You need to add Function as a Reference.

Hey Arul

that’s what I’m confused about. What should I do to call a function within custom code widget without using my own rest client? Is there a service I can invoke? My psuedo code would be something like

foreach(var r in collection)
{
//iterate over collection and call function
var response = functionRequest(r);
}

I am using below code in a function by adding Library in Reference.

var result = this.EfxLib.SysAgentLib.GetClientDir( SysAgent.AgentID) ;
 string lFileDirectory = result ;
4 Likes

Perfect, thank you so much Arul!

To add to the discussion for reference:

Function-to-Function Calls

Use the following format to call another Function: this.EfxLib.[LibraryID].[FunctionID] ([FunctionParameter1], [FunctionParameter2]). For example, a call to the function-1 of the NewLib library can coded like this:

this.EfxLib.NewLib.function_1(1,2);

Note: Use an underscore instead of a dash in a Function ID when you call the Function from your C# code.

Handling Function Output

Single output can be assigned to a Function variable as shown in the below example:

var result = this.EfxLib.NewLib.function_1();

If the called Function returns several response parameters, you need to map each response parameter - for example:

var result = this.EfxLib.Lib_1.Func_1(); 
this.myTsVar = result.r1; 
this.myStrVar = result.r2; 
this.myBoolVar = result.r3;

where r1 , r2 , and r3 are names of response parameters.

6 Likes

So the response from a function if multi-response is just a property of the response body? vs. needing to call it by index?

Enable this setting so that system generates a source code of Functions…
In the appSettings section of the web.config file (<…>\Server\web.config), add this property:

<add key="DumpEfxSources" value="true" />
2 Likes

How to call function to function in same Library?

1 Like

I don’t think you can.

I’m feeling silly here, but I can’t find the Library to add to make this work. Any tips? This is 10.2.500 not 600 - is it a later addition?

I believe they are adding the actual library that contains the function they would like to reference to their current library and then calling it by code. So the library is whatever you called it and you have to add it under References > Libraries in Epicor Functions Maintenance.

I’m not sure if this is possible in 500 but this is how you perform it in 600. Let me know if you are able to reference it.

They have added few improvements between 10.2.500 and 10.2.600. So its part of 10.2.600 and later.

No, there’s no option to add Libraries in 500. This project can’t wait for an upgrade, so I’ll have to do things the repetitive way and see if there’s a chance to refactor later.

At least I know I’m not going mad and not seeing something that’s under my nose.

Team,
I am in 10.2.600 and want to call a function from within the same Library from code. Is there a fancy way to accomplish this?
My hope would be to make use of widgets where I can for BO calls and use code for the logic flow.

Do you want code or do you want to just use widget?

Unofficially you can make it work, it does support it, just you can’t configure it with the current UI.

:innocent:

1 Like

Hoping to call it inline with code. Something like:

if (A == B)
{
  //B = this.CurrentLibrary.OtherFunc(A,true,1);
  this.CurrentLibrary.OtherFunc(A,true,1);
}

Small bump…
This seems like a very important feature to use the current Library’s functions in code.

1 Like

Just wondering how you are achieving this? Are you creating the function call within a function in another library and then copying and pasting into this library?
Is the code for these functions stored somewhere similar to the BPM code .cs files are?

Not being able to use other functions within the same library is a bit of a head scratcher to me. The point of a library is to group related methods, is it not?

At this time you cant call functions from the same library, you could with reflection and code but nothing simple.

In my previous post I just used a Quick Search to self-reference my own library and it works like a charm… However it blocks you from referencing that library with other libraries (circular loop) so I celebrated too early.

I guess your easiest way is just make Function 2 repeat what Function 1 does or have a Frontend Library to your Backend Library.

MyLibInternals
MyLib (which makes heavy use of MyLibInternals Lib).

1 Like