JSON file. Return to Webservice

BUSBOXED
Member Posts: 5
I have a Webservice (Codeunit) that accepts a parameter of DocNo. A search of the Vendor Ledger Entries is carried out and if the External Document No. is found a JSON message is constructed.
I can open the file in Notepad but do not seem to be able to send the values back to the Webservice.
Any help would be appreciated.
I can open the file in Notepad but do not seem to be able to send the values back to the Webservice.
Any help would be appreciated.
0
Answers
-
OBJECT Codeunit 52000 JSON
{
OBJECT-PROPERTIES
{
Date=02/04/20;
Time=22:59:09;
Modified=Yes;
Version List=S214-679;
}
PROPERTIES
{
OnRun=BEGIN
ChatBotGetInvDocNoStatus('123401');
END;
}
CODE
{
PROCEDURE ChatBotGetInvDocNoStatus@2(DocNo@1000 : Text[250]);
VAR
VendLedgEntry@1001 : Record 25;
StatusTxt@1003 : Text[250];
DtldVendLedgEntry@1002 : Record 380;
VendLedgEntryNo@1004 : Integer;
StatusDueNotPaidTxt@1005 : TextConst 'ENG=duenotpaid';
StatusPaidtTxt@1006 : TextConst 'ENG=paid';
StatusNotYetDueTxt@1007 : TextConst 'ENG=notyetdue';
StatusBlockedTxt@1008 : TextConst 'ENG=blocked';
StatusUnknownTxt@1009 : TextConst 'ENG=unknown';
poNumber@1015 : Text[250];
invoiceNumber@1014 : Text[250];
invoiceDate@1013 : Text[250];
dueDate@1012 : Text[250];
company@1011 : Text[250];
status@1010 : Text[250];
Vend@1016 : Record 23;
PurchInvHdr@1017 : Record 122;
BEGIN
VendLedgEntry.RESET;
DtldVendLedgEntry.RESET;
PurchInvHdr.RESET;
CLEAR(VendLedgEntryNo);
CLEAR(status);
VendLedgEntry.SETCURRENTKEY("Document Type");
VendLedgEntry.SETRANGE("Document Type", VendLedgEntry."Document Type"::Invoice);
VendLedgEntry.SETRANGE("External Document No.", DocNo);
IF VendLedgEntry.FINDFIRST THEN BEGIN
IF (VendLedgEntry."Due Date" <= TODAY) AND (VendLedgEntry.Open = TRUE) THEN BEGIN
IF PurchInvHdr.GET(VendLedgEntry."Document No.") THEN
poNumber := PurchInvHdr."Order No."
ELSE
poNumber := '';
invoiceNumber := VendLedgEntry."External Document No.";
invoiceDate := FORMAT(VendLedgEntry."Document Date",0,'<Closing><Day,2>-<Month,2>-<Year>');
dueDate := FORMAT(VendLedgEntry."Due Date",0,'<Closing><Day,2>-<Month,2>-<Year>');
IF Vend.GET(VendLedgEntry."Vendor No.") THEN
company := Vend.Name
ELSE
company := '';
status := StatusDueNotPaidTxt;
OpenJson(BuildJsonUsingJObject(poNumber, invoiceNumber, invoiceDate, dueDate, company, status));
END ELSE BEGIN
IF (VendLedgEntry.Open = FALSE) THEN BEGIN
DtldVendLedgEntry.SETCURRENTKEY("Vendor Ledger Entry No.","Entry Type");
DtldVendLedgEntry.SETRANGE("Vendor Ledger Entry No.", VendLedgEntry."Entry No.");
DtldVendLedgEntry.SETRANGE("Entry Type", DtldVendLedgEntry."Entry Type", DtldVendLedgEntry."Entry Type"::Application);
DtldVendLedgEntry.SETRANGE("Document Type", DtldVendLedgEntry."Document Type"::Payment);
IF DtldVendLedgEntry.FINDSET THEN BEGIN
IF PurchInvHdr.GET(VendLedgEntry."Document No.") THEN
poNumber := PurchInvHdr."Order No."
ELSE
poNumber := '';
invoiceNumber := VendLedgEntry."External Document No.";
invoiceDate := FORMAT(VendLedgEntry."Document Date",0,'<Closing><Day,2>-<Month,2>-<Year>');
dueDate := FORMAT(VendLedgEntry."Due Date",0,'<Closing><Day,2>-<Month,2>-<Year>');
IF Vend.GET(VendLedgEntry."Vendor No.") THEN
company := Vend.Name
ELSE
company := '';
status := StatusPaidtTxt;
OpenJson(BuildJsonUsingJObject(poNumber, invoiceNumber, invoiceDate, dueDate, company, status));
END;
END ELSE BEGIN
IF (VendLedgEntry."Due Date" > TODAY) THEN BEGIN
IF PurchInvHdr.GET(VendLedgEntry."Document No.") THEN
poNumber := PurchInvHdr."Order No."
ELSE
poNumber := '';
invoiceNumber := VendLedgEntry."External Document No.";
invoiceDate := FORMAT(VendLedgEntry."Document Date",0,'<Closing><Day,2>-<Month,2>-<Year>');
dueDate := FORMAT(VendLedgEntry."Due Date",0,'<Closing><Day,2>-<Month,2>-<Year>');
IF Vend.GET(VendLedgEntry."Vendor No.") THEN
company := Vend.Name
ELSE
company := '';
status := StatusNotYetDueTxt;
OpenJson(BuildJsonUsingJObject(poNumber, invoiceNumber, invoiceDate, dueDate, company, status));
END ELSE BEGIN
IF (VendLedgEntry."On Hold" <> '') AND (VendLedgEntry.Open = TRUE) THEN BEGIN
IF PurchInvHdr.GET(VendLedgEntry."Document No.") THEN
poNumber := PurchInvHdr."Order No."
ELSE
poNumber := '';
invoiceNumber := VendLedgEntry."External Document No.";
invoiceDate := FORMAT(VendLedgEntry."Document Date",0,'<Closing><Day,2>-<Month,2>-<Year>');
dueDate := FORMAT(VendLedgEntry."Due Date",0,'<Closing><Day,2>-<Month,2>-<Year>');
IF Vend.GET(VendLedgEntry."Vendor No.") THEN
company := Vend.Name
ELSE
company := '';
status := StatusBlockedTxt;
OpenJson(BuildJsonUsingJObject(poNumber, invoiceNumber, invoiceDate, dueDate, company, status));
END;
END;
END;
END;
END ELSE BEGIN;
poNumber := '';
invoiceNumber := '';
invoiceDate := '';
dueDate := '';
company := '';
status := StatusUnknownTxt;
OpenJson(BuildJsonUsingJObject(poNumber, invoiceNumber, invoiceDate, dueDate, company, status));
END;
END;
PROCEDURE ChatBotGetPODocNoStatus@1(DocNo@1000 : Text[250]) Status : Text[250];
VAR
PurchInvHdr@1005 : Record 122;
VendLedgEntry@1009 : Record 25;
StatusTxt@1008 : Text[250];
DtldVendLedgEntry@1007 : Record 380;
VendLedgEntryNo@1006 : Integer;
StatusDueNotPaidTxt@1010 : TextConst 'ENG=STATUS_DUENOTPAID';
StatusPaidtTxt@1004 : TextConst 'ENG=STATUS_PAID';
StatusNotYetDueTxt@1003 : TextConst 'ENG=STATUS_NOTYETDUE';
StatusBlockedTxt@1002 : TextConst 'ENG=STATUS_BLOCKED';
StatusUnknownTxt@1001 : TextConst 'ENG=STATUS_UNKNOWN';
BEGIN
VendLedgEntry.RESET;
DtldVendLedgEntry.RESET;
PurchInvHdr.RESET;
CLEAR(VendLedgEntryNo);
CLEAR(Status);
PurchInvHdr.SETCURRENTKEY("Order No.");
PurchInvHdr.SETRANGE("Order No.", DocNo);
IF PurchInvHdr.FINDFIRST THEN BEGIN
VendLedgEntry.SETCURRENTKEY("Document Type");
VendLedgEntry.SETRANGE("Document Type", VendLedgEntry."Document Type"::Invoice);
VendLedgEntry.SETRANGE("External Document No.", PurchInvHdr."Vendor Invoice No.");
IF VendLedgEntry.FINDFIRST THEN BEGIN
IF (VendLedgEntry."Due Date" <= TODAY) AND (VendLedgEntry.Open = TRUE) THEN BEGIN
Status := StatusDueNotPaidTxt;
EXIT(Status);
END ELSE BEGIN
IF (VendLedgEntry.Open = FALSE) THEN BEGIN
DtldVendLedgEntry.SETCURRENTKEY("Vendor Ledger Entry No.","Entry Type");
DtldVendLedgEntry.SETRANGE("Vendor Ledger Entry No.", VendLedgEntry."Entry No.");
DtldVendLedgEntry.SETRANGE("Entry Type", DtldVendLedgEntry."Entry Type", DtldVendLedgEntry."Entry Type"::Application);
DtldVendLedgEntry.SETRANGE("Document Type", DtldVendLedgEntry."Document Type"::Payment);
IF DtldVendLedgEntry.FINDSET THEN BEGIN
Status := StatusPaidtTxt;
EXIT(Status);
END;
END ELSE BEGIN
IF (VendLedgEntry."Due Date" > TODAY) THEN BEGIN
Status := StatusNotYetDueTxt;
EXIT(Status);
END ELSE BEGIN
IF (VendLedgEntry."On Hold" <> '') AND (VendLedgEntry.Open = TRUE) THEN BEGIN
Status := StatusBlockedTxt;
EXIT(Status);
END;
END;
END;
END;
END;
END;
Status := StatusUnknownTxt;
EXIT(Status);
END;
LOCAL PROCEDURE OpenJson@4(Json@1003 : Text);
VAR
TempBlob@1001 : Record 99008535;
FileMgt@1000 : Codeunit 419;
BEGIN
TempBlob.WriteAsText(Json,TEXTENCODING::UTF8);
FileMgt.BLOBExport(TempBlob,'ChatBot.json',TRUE);
END;
0 -
LOCAL PROCEDURE BuildJsonUsingJObject@6(poNumber@1009 : Text[250];invoiceNumber@1008 : Text[250];invoiceDate@1007 : Text[250];dueDate@1006 : Text[250];company@1005 : Text[250];status@1003 : Text[250]) Json : Text;
VAR
JObject@1000 : DotNet "'Newtonsoft.Json'.Newtonsoft.Json.Linq.JObject";
JProperty@1001 : DotNet "'Newtonsoft.Json'.Newtonsoft.Json.Linq.JProperty";
JValue@1002 : DotNet "'Newtonsoft.Json'.Newtonsoft.Json.Linq.JValue";
BEGIN
JObject := JObject.JObject;
IF poNumber <> '' THEN
JProperty := JProperty.JProperty('poNumber', poNumber)
ELSE
JProperty := JProperty.JProperty('poNumber', 'null');
JObject.Add(JProperty);
IF invoiceNumber <> '' THEN
JProperty := JProperty.JProperty('invoiceNumber', invoiceNumber)
ELSE
JProperty := JProperty.JProperty('invoiceNumber', 'null');
JObject.Add(JProperty);
IF invoiceDate <> '' THEN
JProperty := JProperty.JProperty('invoiceDate', invoiceDate)
ELSE
JProperty := JProperty.JProperty('invoiceDate', 'null');
JObject.Add(JProperty);
IF dueDate <> '' THEN
JProperty := JProperty.JProperty('dueDate', dueDate)
ELSE
JProperty := JProperty.JProperty('dueDate', 'null');
JObject.Add(JProperty);
IF company <> '' THEN
JProperty := JProperty.JProperty('company', company)
ELSE
JProperty := JProperty.JProperty('company', 'null');
JObject.Add(JProperty);
IF status <> '' THEN
JProperty := JProperty.JProperty('status', status)
ELSE
JProperty := JProperty.JProperty('status', 'null');
JObject.Add(JProperty);
Json := JObject.ToString;
END;
BEGIN
{
S214-679 31.03.2020 MB Initial creation.
}
END.
}
}0 -
Thanks Juhl, I will give it a Try.0
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