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.
Really good! Do you think there’s a way to also pass parameters to the function?
LikeLike
Yes :-). Just replace the Temp Table with your own temp table containing the fields you need.
LikeLike
BTW. This has been made standard in NAV 2018
LikeLike
Standard how? You mean the new API types Pages?
LikeLike
https://docs.microsoft.com/en-us/dynamics-nav/walkthrough-creating-and-interacting-odata-v4-bound-action
LikeLike