Calling a Function from Custom code

Newbie, be gentle :wink:

I have inherited the following,
I have chunk of custom code that executes on a button press on a form.
I would like my custom code to call a function using the REST api.
I already have two examples of this in the custom code, calling other functions in the same library.
So I followed the examples and tweaked for my new function, the code looks like this:

I am debugging the custom code in Visual Studio and I know the above is getting executed.
There are no exceptions being thrown, no error messages.
I have a message popup first thing in the function code, which never shows up.
So it appears Itā€™s not being called

Looking for ideas on how to debug/fix this.

This is Epicor Kinetic 2022 and we are off-premises Epicor hosted,
In this situation is it possible to debug Function code ??

thx, Scott

Iā€™m sure there are other ways, but the simplest Iā€™ve found is to use
Ice.Diagnostics.Log.WriteEntry(ā€œYour DebugDataā€);
to write information into the server event log.

1 Like

:smiling_imp:

Thatā€™s because the function is executed on the server, it has no way to throw a MessageBox to you.

You could return some debug data from your function, write to the Event Log, etc.

Gimme a minute or two and Iā€™ll dig up some relevant threads.

2 Likes

MessageBox.Show() is for client side customization

Infomessage.Publish() will send a message through a BPM. Although, if you get more than a layer down (a bpm calling another bpm etc) many times they wonā€™t show.

My function does throw up a message (I didnā€™t mean literally Message.Show()).

I know this cause my function is also used by a BPM that is tied to a form and when itā€™s invoked I get the message. (wouldnā€™t that be a similar case, or no ?)

This is the code Iā€™m using in my function to show the message:

image

butā€¦putting debug data in there isnā€™t going to help me because this is the first line in my function and it doesnā€™t appear.

I donā€™t believe Iā€™ve ever been able to get an infomessage.publish back from a function.
I could be mistaken.

How to write to task log from scheduled Functions

BPM Logging Snippet

How to write your own trace logs

Have you tried running this function through the built in swagger page, curl, or postman?

woah, thereā€™s a epicor built in swagger page ?!?

Iā€™m very familiar with swagger and postman,
if there is a built in epicor swagger page please tell me where

Thanks

You poor soul.

https://yourserverinstance/apps/resthelp/#/home
https://yourserverinstance/api/help/v1/index.html
https://yourserverinstance/api/help/v2/index.html

You can also install the MS Remote Debugger on the server and debug your functions that way. I have done it with BPMs and now am with Functions. It is a nice way to debug your code.

Ok, swagger gave me:
500 Internal server error. Server is unable to process the request.

Iā€™m still confused about why it works in my method directive (call function)
but not my custom codeā€¦call function

they both are running server side correct ?

What do you mean your ā€œCustom codeā€?

Is this a screen customization? Those are run client side.

If you are cloud, Ice.Diagnostics.Log.WriteEntry(ā€œā€); can be viewed with my dashboard:

Server Event Log Dashboard

Use ā€œEpicor App Serverā€ as the Event Log name on the side.

1 Like

Heā€™s calling a function from the client through the rest helper.

Yes, I have a screen customization calling a function (code function not widget function) via rest api.

I also have a method directive calling the same function.

the first thing the function does is pop open a message (which works when calling from the bpm)
but calling the function from the screen custom code does not

this (and the swagger response) makes me believe itā€™s not even getting to my function in the screen customization case

so, 1. if you can do it on the server side, do it there. Future you will thank you.

  1. I believe the rest client on the classic screens are broken, and I donā€™t know if theyā€™ve ever been fixed.

On Swagger your message Info will show up as a header under CallContext. If you are getting 500 on Swagger thereā€™s ssomething else wrong with your function.

1 Like

Itā€™s not going to. Itā€™s a miracle it gets passed back from the bpm that triggers it.

ā€œon the sideā€ ? I donā€™t see it, sorry

That link was in case you are cloud and wanted to use my dashboard to see the event logs.
No way you read that thread yet :rofl: