- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2018 07:09 AM
hi everybody,
I´m trying to create an object of type "Name-Value Pairs" in my script. I do not know how!?
The only workaround is to create table "u_test" with column "u_param" (type Name-Value Pairs) and do the following:
var gr = new GlideRecord("u_test");
gr.initialize();
gr.u_param["pe_sysid"] = "testvalue1";
gr.u_param["bt_sysid"] = "testvalue2";
Then I get the object gr.u_param of type "Name-Value Pairs" as I want.
How can I create such an object without workaround using an existing table? A "normal" java script object like {"par1":"val1","par2":"val2"} does not work!
Thanks so much for help
Regards Andre
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2018 07:55 AM
How can I create such an object without workaround using an existing table? A "normal" java script object like {"par1":"val1","par2":"val2"}
-There is no specific field type in a Table to store a Javascript Object.(As you said you dont want to use type Name-Value Pairs Field)
If you dont want to use type Name-Value Pairs field type, then Create a field of type String to store your object {"par1":"val1","par2":"val2"} and perform JSON Encoding and decoding to read and write to the object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2018 07:18 AM
Hi Andre,
Can you explain in detail what you want to achieve?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2018 07:38 AM
I want to create an object of type "Name-Value Pairs" which I can use as input for subworkflow.
1. Create Workflow
2. Workflow has a run script which is creating object of type "Name-Value Pairs", see above
workflow.scratchpad.u_param = gr.u_param;
3. Use a subworkflow in 1. workflow via "Parallel Flow Launcher" which is getting as INputs:
[{u_param: workflow.scratchpad.u_param}]
4. run script in subworkflow 3. is getting the u_param and uses it
With above workaround by using table to create the object it works like:
var gr = new GlideRecord("u_test");
gr.initialize();
gr.u_param["pe_sysid"] = "testvalue1";
gr.u_param["bt_sysid"] = "testvalue2";
var u_param = gr.u_param;
But I´m not able to create object like:
var u_param = {"par1":"val1","par2":"val2"};
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2018 07:55 AM
How can I create such an object without workaround using an existing table? A "normal" java script object like {"par1":"val1","par2":"val2"}
-There is no specific field type in a Table to store a Javascript Object.(As you said you dont want to use type Name-Value Pairs Field)
If you dont want to use type Name-Value Pairs field type, then Create a field of type String to store your object {"par1":"val1","par2":"val2"} and perform JSON Encoding and decoding to read and write to the object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2018 01:16 PM
Hi Aman, you´re right. Simple array like metioned:
var u_param = {"par1":"val1","par2":"val2"};
worked for me too now.
My mistake was to use array variable directly. Converting to JSON.stringify(parsedData) solved the issue 🙂
Thx