Fetch 'Template values' from sys_template table and store the values in catalog item fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2022 02:27 AM
My Requirement is I have a field called 'Select Template' on a catalog item which is reference field to sys_template table. When I select any template the template values should be auto populated in catalog item fields on catalog form.
i wrote below catalog client script:
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading || newValue == ''){
return;
}
var template = g_form.getValue('Template');
if(template != '')
//Apply the selected template
applyTemplate(template);
}
But this is not working as expected. Since the template values are stored as XML attached in the screenshot. I want to extract the values from template values and split them separately to populate the values in catalog item fields.
Finally I want to populate catalog item fields whenever I select a template.
Please can anyone help me out to write catalog client script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2022 02:55 AM
This might help-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var reg = g_form.getReference('variable', callBackMethod); // your variable name here
}
function callBackMethod(ref){
var str = ref.template; //this should give you the encoded query
var categoryValue = str.substring(str.indexOf('category=') + 9, str.indexOf('^'));
var platformValue = str.substring(str.indexOf('u_platform=') + 11, str.indexOf('^'));
alert(categoryValue);
alert(platformValue);
}
https://community.servicenow.com/community?id=community_question&sys_id=75d1445edbb95010b1b102d5ca96197c
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2022 03:16 AM
My instance has restriction for getReference and GlideRecord operations in catalog client script.
I want to achieve it using other logic.
Since I am getting the sys_id of the template applied in alert, I want to query the table and fetch template values to populate in the fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2022 03:24 AM
I think, gliderecord is necessary to query a table, we use some conditions such as gr.addQuery() , gr.Query() to query the table through GlideRecord.
You may store the values in script include and then call it from client script. Just curious to know, how is it possible to have restriction of gliderecord, getreference restrictions in client script, it is allowed in OOB way.
Please mark helpful/correct if it added value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2022 04:54 AM