I've been trying to run a NAV function (Microsoft Dynamics 365 Business Central) from microsoft's odata client. when I create an odatav4 data source, and import the $metadata, I was able to include the codeunits functions in the autogenerated code, this creates a DataServiceActionQuery types for me:
/// <summary>
/// There are no comments for Funcions_TestFunction in the schema.
/// </summary>
[global::Microsoft.OData.Client.OriginalNameAttribute("Funcions_TestFunction")]
public virtual global::Microsoft.OData.Client.DataServiceActionQuery Funcions_TestFunction(string param1, string param2, string param3)
{
return new global::Microsoft.OData.Client.DataServiceActionQuery(this, this.BaseUri.OriginalString.Trim('/') + "/Funcions_TestFunction", new global::Microsoft.OData.Client.BodyOperationParameter("param1", param1),
new global::Microsoft.OData.Client.BodyOperationParameter("param2", param2),
new global::Microsoft.OData.Client.BodyOperationParameter("param3", param3));
}
when I try to run it, I have to pass the company code to it, but I don't know how to do it:
Uri texte = new Uri(@"http://192.168.0.18:18148/Instancename/ODataV4/");
NAV.NAV x = new NAV.NAV(texte);
x.Credentials = credentials;
DataServiceActionQuery funcionini = x.Funcions_TestFunction(param1, param2, param3);
funcionini.Execute();
with the DataServiceQuery ( pages published) I have no problems to pass it, simply add query option:
DataServiceQuery<NAV.Customer> z = x.Customer.AddQueryOption("company", "Mycompany");
IEnumerable<NAV.Customer> resultat = z.Where(f => f.Type == "something").OrderBy(f => f.Name);//.GetAllPages();
sample with postman ( at the end you can see the url parameter: ?company=mycompany )

Insert Company
"MyCompany"the company in the URL:BuildingRequestto do that:Sample Code
In the generated NAV class I added the
Credentialsand theBuildingRequest. I also addedSendingRequest2andReceivingResponsefor debugging:Then you should be able to call your function:
My code generation tool generated
DataServiceActionQuerySingleinstead ofDataServiceActionQuery. I guess this depends on how functions are defined in NAV. I call functions like this: