We are working with NAV_BC14 using C/AL code.
My Jason Code is as follow:
****************************
//
Create Json
IF ISNULL(StringBuilder) THEN
Initialize;
SalesHeader.SETRANGE("Document Type",SalesHeader."Document Type"::Order);
SalesHeader.SETFILTER("No.",'2258634');
IF SalesHeader.FINDFIRST THEN
//JsonTextWriter.WriteStartArray;
BEGIN REPEAT
JsonTextWriter.WriteStartObject;
JsonTextWriter.WritePropertyName('DocumentNo');
JsonTextWriter.WriteValue(SalesHeader."No.");
//Create Branch of Address Start
JsonTextWriter.WritePropertyName('Address');
JsonTextWriter.WriteStartObject;
JsonTextWriter.WritePropertyName('Address1');
JsonTextWriter.WriteValue(SalesHeader."Sell-to Address");
JsonTextWriter.WritePropertyName('City');
JsonTextWriter.WriteValue(SalesHeader."Sell-to Customer Name");
JsonTextWriter.WriteEndObject;
//Create Branch of Address End
//Create Array of Item Details Start
JsonTextWriter.WritePropertyName('ItemDetails');
JsonTextWriter.WriteStartArray;
SalesLine.SETRANGE("Document Type",SalesHeader."Document Type");
SalesLine.SETRANGE("Document No.",SalesHeader."No.");
IF SalesLine.FINDSET THEN
REPEAT
JsonTextWriter.WriteStartObject;
JsonTextWriter.WritePropertyName('ItemNo');
JsonTextWriter.WriteValue(SalesLine."No.");
JsonTextWriter.WritePropertyName('PrName');
JsonTextWriter.WriteValue(SalesLine.Description);
JsonTextWriter.WriteEndObject;
UNTIL SalesLine.NEXT =0;
JsonTextWriter.WriteEndArray;
JsonTextWriter.WriteEndObject;
UNTIL SalesHeader.NEXT =0;
END;
JsonTextWriter.Flush;
JSonString:=GetJSon;
MESSAGE(JSonString);
now how can I export this String as a Text File? can anyone help?
0
Answers
I normally create a function which asks for the string as a parameter, purely to check the full result.
If you create a second parameter for file location you could use it to really save the Json somewhere dynamically, and reuse the function if needed.