JSON Object - How to create?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 11:06 AM
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.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 12:10 PM
Okay,
Here is what I have, but I'm getting nothing for input1 and 2 and there are values in these variables. Ideas?
if (uatm.u_orch_name_add != '' && uatm.u_orch_name_add != undefined) {
var obj = {"input1": uatm.u_input_parm_1_add.u_input_parm_1,"input2": uatm.u_input_parm_2_add};
var parser = new JSON();
var str = parser.encode(obj);
//test
//var obj = parser.decode(str);
gs.log('The object ' + str);
The object {"input1":{},"input2":{}}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 05:56 PM
JSON.stringify() - JavaScript | MDN
and JSON().decode
i,.e:
var str = {"type":"myType","description":"myDescription","message":"{\"url\":\"http://www.something.com\"}"}
var obj = new JSON().decode(str);
gs.log(str['message']);
Will print:
[0:00:00.001] Script completed in scope global: script
*** Script: {"url":"http://www.something.com"}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2017 06:37 AM
I'm not sure how to get the variables to show data in the JSON string. I can't put quotes around the variables, because then the text of the variable name comes through to the JSON string. Ideas on how to get the actual value in the JSON string and not the name of the variable?
if (uatm.u_orch_name_add != '' && uatm.u_orch_name_add != undefined) {
var obj = {"input1": uatm.u_input_parm_1_add.u_input_parm_1,"input2": uatm.u_input_parm_2_add};
var parser = new JSON();
var str = parser.encode(obj);
//test
//var obj = parser.decode(str);
gs.log('The object ' + str);
The object {"input1":{},"input2":{}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2017 06:48 AM
You would have to put it in a string with mixed single quote and double quotes, like:
'{"input1":' + uatm.u_input_parm_1_add.u_input_parm_1 + ',"input2":' + uatm.u_input_parm_2_add + '}';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2017 07:56 AM
Thank you -
I have this now:
if (uatm.u_orch_name_add != '' && uatm.u_orch_name_add != undefined) {
var obj = '{"input1":' + uatm.u_input_parm_1_add.u_input_parm_1 + ',"input2":' + uatm.u_input_parm_2_add + '}';
var parser = new JSON();
var inputparms = parser.encode(obj);
gs.log('The object ' + inputparms);
The object "{\"input1\":AANurseGroup,\"input2\":nUCMiU9ApkSQRMx8TMo5RA==}"
When I use the following to decode, I get nada...
//test
var str = parser.decode(inputparms);
gs.log(str['input2']);
undefined
Ideas on how to decode and call input2?