Maximo Automation Script for Integration - JSON

Viewed 946

I'm writing a script for integration to modify JSON input and save to maximo. First I converted the StructureData erData input to JSON object like this;

var resp = JSON.parse(erData.getDataAsString());

Then I modified the JSON object to add additional properties. How can I convert back my modified JSON object to StructureData erData so that I can save it to Maximo.

Thank you. Regards

2 Answers

To convert back the modified JSON object to StructureData erData by using JSON.stringify() javaScript method as follows :

Say, your resp has following stringify data : '{"result":true, "count":42}'

var resp = JSON.parse(erData.getDataAsString());  // resp = '{"result":true, "count":42}';
resp['name'] = 'Dummy';                           // a new property with key name and value Dummy is created and added in resp
console.log(resp);                                // you get the new resp object
console.log(JSON.stringify(resp));                // '{"result":true, "count":42, "name":"Dummy"}'

In case for Maximo to work, follow the JSON String from JSON Object Maximo

Hope this helps !!

Looking at the Maximo JavaDocs for StructureData, and not being sure how thorough it is, you could try StructureData(JSON.stringify(resp)). If that doesn't work, you may need to convert your JSON to XML and pass the XML as a byte array to a StructureData constructor.

Alternatively, use the StructureData methods to manipulate erData directly, without converting to/from JSON.

Related