How to call Function in C#

What do you need to call a Function in a screen customization (without REST)? I can’t find any documentation that tells me what is needed.

He’s talking about an epicor function library function, not a generic programming question.

John, there are some recent examples here if you search for calling functions in customization. Two ways to do it, either with the restclient shipped with higher versions or with a plain old build it yourself http client. I posted an example a few days ago of using the restclient but I have another example if you’re wanting to use http client

4 Likes

Ah, when I searched all I could find was REST examples and I am not quite there yet. I guess I will have to just code it in the screen and copy paste if I want to use it again.

Thanks @Aaron_Moreng

@jkane
The 10.2.600 version of the Customization user Guide added a section called ‘Custom Methods & Epicor Functions’ under the Advanced Customization section. I found it VERY helpful in calling the function from a Customization. The most shocking thing was the sample code worked the first time for me!
Essentially to call the Function you call the REST API.
As a side note, I’m suspect this will be the direction that Kinetic customizations will go for calling BO Methods as well, so it’s good practice and it’s actually not that hard.

4 Likes

Correct Rick - often logic in the UI is more business logic than client side validation - if BPM’s are not the correct place leverage functions that allow you to orchestrate what you need.

2 Likes

In other words, you can’t call a function unless you use rest or http client?

Directly from WinForms/SmartClient UIs, it seems the answer is no. I haven’t looked into it myself but I also haven’t seen anything to suggest it to be an option and I can’t imagine it being seen as a priority to support.

However, Epicor Functions can easily be called by Kinetic UIs, REST APIs and BPMs (including uBAQ ones) therefore there are lots of ways to still call them usin slight workarounds. What was the purpose that you were hoping to use an Epicor Function for?

Example code for calling a function from a BPM.

string functionLibrary =  "TestLib";
string function =  "TestFunc";
var result = (Tuple<System.Boolean, System.String>)this.InvokeFunction(functionLibrary,function,Tuple.Create(this.ds));
var outputBool = result.Item1;
var outputStr = result.Item2;
1 Like

Hey Callum, I was running into an issue where I could create my own function to update a UD table, but was having trouble coding it so I thought, I’ll just create a function and then call it from c# code on my form customization…

Fair enough. If the updates to the UD table data are based on the maintenance or entry of the primary form data then using a server side BPM is nearly always going to be the easiest, most reliable, and most efficient/performant option.

If, however, you’re wanting to directly read AND write data to the UD table, then there is a good chance the UI customization option would be the easier and better option, while potentially using the wizard functionality in the customization tools menu to assist with the base code.

Epicor Function capabilities are great and will only be even more important in Kinetic going forwards but for plenty of existing SmartClient UI/Data purposes, they’re not really going to be the most useful/best tools for the job. Unless it’s to abstract out logic for re-use or separation from BPMs mainly.

You actually can quite easily with the Rest helper (look in the Epicor Help)

3 Likes

I like the rest helper. I was just wondering if there was a business object and method we could call like any other adapter on the UI.

It’s just a helper class (the RestClient), what do you want to have a special business object for?

I don’t… I just thought it would be something I could reference in the “Business Logic Method Call” wizard and it seems that it isn’t.

If it is a helper class then it’s a helper class, cool with me! :grinning: :call_me_hand:

1 Like

As I am searching for another post here it is yet again telling me to use Epicor Help… :man_facepalming: