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: