Does Nav dynamic version <> support JSON processing? I have a scenario to call external web service(REST), which takes in JSON and responds back in JSON. How to construct and parse JSON data in NAV.
Creating JSON data in NAV is quite easy. Parsing JSON data is possible, but can be tricky, depending on the actual data structure. As you will need .NET for the webservice call it might be a good idea to build an external assembly using JSON.NET http://james.newtonking.com/json, for example. Using the library directly from NAV is hard to impossible, because it uses some .NET constructs that aren't accessible from NAV. I would use the .NET approach if it should only be deployed on one server and try to do it in NAV with standard .NET libraries if it should be deployed on more systems.
Let me know if you need an example of creating JSON in NAV or if you need help with JSON.net.
Creating JSON data in NAV is quite easy. Parsing JSON data is possible, but can be tricky, depending on the actual data structure. As you will need .NET for the webservice call it might be a good idea to build an external assembly using JSON.NET http://james.newtonking.com/json, for example. Using the library directly from NAV is hard to impossible, because it uses some .NET constructs that aren't accessible from NAV. I would use the .NET approach if it should only be deployed on one server and try to do it in NAV with standard .NET libraries if it should be deployed on more systems.
Let me know if you need an example of creating JSON in NAV or if you need help with JSON.net.
Thanks for your offer to help.
The following the data structure for JSON request and Response.
Request:
{
"type": "NEWItem_REQUEST:#NewItem",
"requestId": "PRE-PE-Item",
"partDescr": "Test",
"uom": "EA",
"Price": 10
}
Response:
{
"SendNEWItem_REQUESTResult": {
"DangeroudCode": "O",
"Flag": "N",
"OrderQuantity": 0,
"errorTable": [
{
"errorItem": "itemNumber",
"errorCode": "00",
"errorMessageShort": "Item Successfully Added",
"errorMessageLong": "New Item [1909876] was successfully created"
}
],
"inventoryClass": "ABC",
"secondaryVendorId": "",
"flameFlag": "N",
"catalogs": "LM"
}
}
I'll explain my case a bit more. In my case, Nav cannot create an Item with out a corresponding Item being created in a legacy application. Right now this is handled by Job Queues which is executed during non working hours. In short there is a one day delay. What we are trying to do is to interact with the Legacy application using web service: Nav send the request to the legacy applications web service and receives the response back when the Item is created.
"I would use the .NET approach if it should only be deployed on one server and try to do it in NAV with standard .NET libraries if it should be deployed on more systems."
Based on your above comment, I guess I will have to use standard .NET libraries in Nav.
Mode := 1;
FOR i := 1 TO STRLEN(Value) DO BEGIN
case mode of
0: // Search for key end
BEGIN
IF Value[i] = '"' THEN BEGIN
Mode := 6;
END ELSE Key := Key + FOrmat(Value[i]);
END;
1: // Search for key begin
BEGIN
IF Value[i] = '"' THEN BEGIN
Mode := 0;
END;
END;
2: // Handle complex data types not required in this case...
BEGIN
//message('Complex Type ' + Key);
Key := '';
IF Value[i] = '"' THEN Mode := 0
else Mode := 1;
END;
3: // Search for Value end
BEGIN
IF Value[i] = '"' THEN begin
Mode := 1;
ProcessKeyValue(Key, KeyValue);
Key := '';
KeyValue := '';
end ELSE KeyValue := KeyValue + Format(Value[i]);
END;
4: // Search for Value begin
BEGIN
IF (Value[i] = '{') OR (Value[i] = '[') THEN
Mode := 2;
IF Value[i] = '"' THEN
Mode := 3;
IF Value[i] IN ['0'..'9'] THEN begin
KeyValue := KeyValue + Format(Value[i]);
Mode := 5;
end;
END;
5: // Numeric value
BEGIN
IF Value[i] IN ['0'..'9'] THEN
KeyValue := KeyValue + Format(Value[i])
ELSE begin
Mode := 1;
ProcessKeyValue(Key, KeyValue);
Key := '';
KeyValue := '';
end;
END;
6: // Search for :
BEGIN
IF Value[i] = ':' THEN MOde := 4;
END;
END;
END;
With the code above I could parse the JSON you posted. It does not work for all JSON results, but hopefully give you an idea how it is possible to implement a JSON parser in NAV.
Hi,
just for the case someone is interested:
for connecting a Navision with Shopware i wrote my own REST/JSON Wrapper direct in Navision without any additional software.
Natural there is a external component, but only Microsoft components you find on every Windows-computer since 2003/Xp, so you don't need to setup any DLL's, programms or whatever on the using client computers.
Currently the page is only in German because Shopware is very (only?) popular in Germany, but the examples are easy to read (just ignore the german text).
If you want to drive a Shopware system out of Navision you might also be interested in a complete PIM Solution direct inside of Navision.
Also in German but with a lot of explaining Pictures:
Hello
I visited your German Navision Shopware page - I'm looking for help to make up a specific Navision code to communicate with JSON - Can you tell me more about your api code unit ?
Thanks
Comments
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Let me know if you need an example of creating JSON in NAV or if you need help with JSON.net.
http://www.sist.biz/en/ [en] | http://www.sist.biz [de]
Thanks for your offer to help.
The following the data structure for JSON request and Response.
Request:
{
"type": "NEWItem_REQUEST:#NewItem",
"requestId": "PRE-PE-Item",
"partDescr": "Test",
"uom": "EA",
"Price": 10
}
Response:
{
"SendNEWItem_REQUESTResult": {
"DangeroudCode": "O",
"Flag": "N",
"OrderQuantity": 0,
"errorTable": [
{
"errorItem": "itemNumber",
"errorCode": "00",
"errorMessageShort": "Item Successfully Added",
"errorMessageLong": "New Item [1909876] was successfully created"
}
],
"inventoryClass": "ABC",
"secondaryVendorId": "",
"flameFlag": "N",
"catalogs": "LM"
}
}
"I would use the .NET approach if it should only be deployed on one server and try to do it in NAV with standard .NET libraries if it should be deployed on more systems."
Based on your above comment, I guess I will have to use standard .NET libraries in Nav.
Call the webservice, if you're using 2013 you can use WCF or the WebClient from the .NET framework (see http://msdn.microsoft.com/en-us/library/hh169399(v=nav.71).aspx, http://www.asp.net/web-api/overview/web-api-clients/calling-a-web-api-from-a-net-client)
If you're using 2009 you can also use the MSXML automation (it can also process text).
Parsing the JSON data:
With the code above I could parse the JSON you posted. It does not work for all JSON results, but hopefully give you an idea how it is possible to implement a JSON parser in NAV.
http://www.sist.biz/en/ [en] | http://www.sist.biz [de]
just for the case someone is interested:
for connecting a Navision with Shopware i wrote my own REST/JSON Wrapper direct in Navision without any additional software.
Natural there is a external component, but only Microsoft components you find on every Windows-computer since 2003/Xp, so you don't need to setup any DLL's, programms or whatever on the using client computers.
Currently the page is only in German because Shopware is very (only?) popular in Germany, but the examples are easy to read (just ignore the german text).
https://sites.google.com/site/renethoen ... e-mit-josn
If you want to drive a Shopware system out of Navision you might also be interested in a complete PIM Solution direct inside of Navision.
Also in German but with a lot of explaining Pictures:
https://sites.google.com/site/renethoene/navision/pim
Hope i can help someone with this. Both Solutions are also to sell. Documentation will be more in the future.
I visited your German Navision Shopware page - I'm looking for help to make up a specific Navision code to communicate with JSON - Can you tell me more about your api code unit ?
Thanks