JSON Object - How to create?

rebecca75
Tera Contributor

I have a field on the Task table called 'u_input_parms' that will be used in orchestration. The idea is to have this field as a JSON Object

that I'll use to pass values into my workflow/orchestration.

Currently, the 'u_input_parms' field will have 'workflow name' to fire, input_parm1 and input_parm2.

My question, how do I create this field as a JSON object so that I can call 'Input_parm1' etc? We are on Helsinki and my understanding

is that the json function isn't available until a later version.

11 REPLIES 11

Mike Allen
Mega Sage

You could just store is as a string of name/value pairs and use new global.JSON().encode(current.field); to pass it to orchestration.


Patrick Schult2
Giga Guru

You don't need to use any kind of special field to store JSON, you can just use a String field. The idea is that you put the raw JSON into this field on your Incident (or whatever) and then parse it whenever you need to actually use it.



Helsinki supports the native JSON object in JavaScript, which is all you need to serialize and de-serialize an object.



Docs on JSON: https://developer.servicenow.com/app.do#!/api_doc?v=helsinki&id=c_JSONAPI



Docs on JSON.parse: https://developer.servicenow.com/app.do#!/api_doc?v=helsinki&id=r_JSON-parse_S


Thank you -



I updated the code to this:



if (uatm.u_orch_name_add != '' && uatm.u_orch_name_add != undefined) {


var inputparm = '{"input1":"' + uatm.u_input_parm_1_add.u_input_parm_1 + '","input2":"' + uatm.u_input_parm_2_add + '"}';


var obj = inputparm;


var parser = new JSON();


var str = parser.encode(obj);



//test


var obj = parser.decode(str);


gs.log('The object '   + obj.input1);



However, I get this and I not the actual value... I'm obviously missing some quotes someplace...



The object ' + uatm.u_input_parm_1_add.u_input_parm_1 + '


Scratch this - I got a little cra-cra with the quotes and forgot to remove the +....I will tweak...