- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2020 08:02 PM
Hi ServiceNow Community Developers,
Do you guys know if one can use the g_form.setValue() API in a name value pairs field? If so would you please provide examples of how one can go about in doing that.
Thanks,
John
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2020 09:42 PM
Hi,
you need to parse the array of json objects
Sample below
var arr = '[{"variable":"jm_template_variable","type":"xlrelease.StringVariable"},{"variable":"jm_template_var2","type":"xlrelease.StringVariable"},{"variable":"jm_date","type":"xlrelease.DateVariable"},{"variable":"jm_boolean","type":"xlrelease.BooleanVariable"},{"variable":"jm_array","type":"xlrelease.ListStringVariable"},{"variable":"jm_integer","type":"xlrelease.IntegerVariable"}]';
var parser = JSON.parse(arr);
var obj = {};
for(var i=0;i<parser.length;i++){
obj[parser[i].variable] = parser[i].type;
}
g_form.setValue('u_name_value', JSON.stringify(obj));
Output:
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
11-15-2020 08:22 PM
you need to set json string using the g_form.setValue()
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
11-15-2020 08:37 PM
Hi Ankur,
Thanks for your response, would you please provide an example.
For instance lets say i have a json object that has the name and the value and i want to set up the name value pair field on a form using the name and value that I have on my json object how would I go about doing that? Kindly advise please.
Thanks,
Johannes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2020 08:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2020 09:34 PM
Hi Ankur,
Thank you so much this was very helpful.
One more question please if you don't mind, let's i have a an array of json objects like
[{"variable":"jm_template_variable","type":"xlrelease.StringVariable"},{"variable":"jm_template_var2","type":"xlrelease.StringVariable"},{"variable":"jm_date","type":"xlrelease.DateVariable"},{"variable":"jm_boolean","type":"xlrelease.BooleanVariable"},{"variable":"jm_array","type":"xlrelease.ListStringVariable"},{"variable":"jm_integer","type":"xlrelease.IntegerVariable"}]
so basically i want to dynamically set the name value pair field so that it has the 6 names and values like in my array above -
where name property is jm_template_varaible and it's value is xlrelease.StringVariable and so on so that in the end my name value pairs field has six occurences like my json array above. Do you know if this is possible.
Thanks,
Johannes