Thursday, April 23, 2020

Accept DotNet JSON as Text in Microsoft Dynamics Navision

Hi Readers,

NAV doesn't accept .net Data source i.e., JSON as a parameter. But what if we want to pass a .net Data source in a NAV function to access its properties. 

Here is a short blog for that! 

We can pass .net Data in a form of Text as parameter in NAV and this is how that can be done. 

Consider,


.NET Data Source and it's properties aa shown below: 
public class Customer
{
[Datacontact]
public string CustomerNo {get; set; }
[Datacontact]
public string Name {get; set; }
}

Create a function in NAV and add a parameter as Text. This Text Data will be the one coming from a .NET Application or Service. 

Now is the mail part wherein we have to break thi string and use the properties. We will require Serialisation for that. Write the line as shown below: 

Customer := Serializer.DataContractJsonSerializer(GETDOTNETTYPE(Customer)).ReadObject(MemStream.MemoryStream(Encoding.UTF8.GetBytes(FORMAT(jsonData))));

wherein, Customer is the Dot.net (Data sources as shown above) variable and jsonData is the Data coming from that Data source.


This was a short blog but an important one. This information is useful where you have to Integrate a .net applications or any third party application with NAV.

Please stay tuned for the INTEGRATION blog which is coming next!

Write your suggestions in the comment section.
You can also email me at: jyotsnaoberainav@gmail.com

Also visit my website JONAV if you need help with any NAV/BC Services!

Thank you!


No comments:

Post a Comment