Call Function or Codeunit using ODATA

REST Web Service is the future, no doubt about that, but in Dynamics NAV you can only expose the Page and Query object through ODATA. So how do you Run a codeunit or function, if you want to initiate a process from a Web Service call, like we can in SOAP through exposed Codeunit?

This can be done through a page object this way.

Create a new Page, and set the SourceTable to TempBlob (or create your own temp table)
Set SourceTableTemporary to Yes
Add the “Primary Key” field to the page.2017-05-26_1040

Add a Case statement in the OnInsertRecord trigger in the Page, and add all the functioncalls you need to call.

2017-05-26_1042
Expose the Page as a Web Service

Now you call the ODATA endpoint with a POST method and send the number of the function in the Primary_Key field.

JSON example:
{
“Primary_Key”: 2
}

I do not recommend calling long running process this way.
Instead write to the Job Cue to make a schedule and let NAS do the work.

5 thoughts on “Call Function or Codeunit using ODATA

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s