Create an object type "Name-Value Pairs"

Andre27
Tera Contributor

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

 

 

 

1 ACCEPTED SOLUTION

ARG645
Tera Guru

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. 

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Andre,

Can you explain in detail what you want to achieve?

Regards

Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Andre27
Tera Contributor

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

 

ARG645
Tera Guru

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. 

Andre27
Tera Contributor

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