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.

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

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.