Create JSON file using C/AL Code

navuser1
Member Posts: 1,334
Dear Sir,
Suppose I'm using standard nav 2016 database & want to create a JSON file on Customer Master tabledata.
So how can I do that using C/AL code ?
Kindly reply.
navuser1
Suppose I'm using standard nav 2016 database & want to create a JSON file on Customer Master tabledata.
So how can I do that using C/AL code ?
Kindly reply.
navuser1
Now or Never
0
Answers
-
Either implement your own, or backport Codeunit 5459 JSON Management from newer NAV and use functions there to generate your JSON0
-
There are also several useful functions on Table 1236 - backport that tooKyle Hardin - ArcherPoint0
-
I will checkNow or Never0
-
kylehardin wrote: »There are also several useful functions on Table 1236 - backport that too
Which version of NAV I have to look for ?Now or Never0 -
I think that was introduced in NAV 2017. 2018 for sure.Kyle Hardin - ArcherPoint0
-
I will collect the same. BTW, I just want to know that Nav is able to create JSON thru its C/AL ?Now or Never0
-
code for iteration(Loop) to create a JSON file ?Now or Never0
-
I don't have any sample code for constructing a JSON file, but table 1236 has lots of functions attached for JSON data handling. I've put some sample code below, but this reads data from a JSON file rather than trying to construct a JSON file. I think the process would basically be to add data to the JSON table, and then call a method that exports that as JSON into a BLOB.
My advice would be to make yourself a docker container with NAV 2018. Pull out all of the objects as text, and see if you can find any example code in those objects that is calling and using Table 1236.
PROCEDURE BingDistance@1240060001();
VAR
TempBLOB@1240060005 : Record 99008535;
JSONBuffer@1240060010 : TEMPORARY Record 1236;
HTTPWebRequestMgt@1240060002 : Codeunit 1297;
WebOutStream@1240060004 : OutStream;
WebInStream@1240060003 : InStream;
HTTPStatusCode@1240060008 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpStatusCode";
ResponseHeaders@1240060006 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Collections.Specialized.NameValueCollection";
URL@1240060000 : Text;
Response@1240060007 : Text;
Mileage@1240060011 : Decimal;
BEGIN
URL := 'https://dev.virtualearth.net/REST/v1/Routes/DistanceMatrix?origins=3.98344,-8.20666&destinations=3.78122,-8.39699';
URL := URL + '&travelMode=driving&startTime=2:00:00-05:00&distanceUnit=mile';
HTTPWebRequestMgt.Initialize(URL);
IF NOT GUIALLOWED THEN
HTTPWebRequestMgt.DisableUI();
HTTPWebRequestMgt.SetReturnType('application/json');
CLEAR(TempBLOB);
CLEAR(WebInStream);
TempBLOB.Blob.CREATEINSTREAM(WebInStream);
IF NOT HTTPWebRequestMgt.GetResponse(WebInStream, HTTPStatusCode, ResponseHeaders) THEN BEGIN
HTTPWebRequestMgt.ProcessFaultResponse(Response);
ERROR(Response);
END;
WebInStream.READTEXT(Response);
CLEAR(JSONBuffer);
JSONBuffer.ReadFromText(Response);
IF JSONBuffer.GetDecimalPropertyValue(Mileage, 'travelDistance') THEN
MESSAGE(FORMAT(Mileage));
END;Kyle Hardin - ArcherPoint0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions