- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2019 08:03 AM
Hello Developers,
I am trying to call a script include from an onchange client script and populate a u_Field. The script include returns a group. The client script needs to supply the cmdb_ci and the group type.
I've been attempting to use something similar to: https://community.servicenow.com/community?id=community_question&sys_id=a77707a1dbc023c09d612926ca961925&view_source=searchResult
with little luck.
Here is the script include:
var Group_and_CI = Class.create();
Group_and_CI.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getallValues : function() {
var output;
var grp = this.getParameter("sysparm_grp");
var cmdb = this.getParameter("sysparm_ci");
var gr = new GlideRecord('u_m2m_groups_configuratio');
gr.addQuery('u_group', grp);
gr.addQuery('u_configuration_item', cmdb);
gr.query();
if(gr.next()) {
output += gr.sys_id+"\n";
}
return output ;
},
type: 'Group_and_CI'
});
Can someone help me with the Change client script?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2019 12:00 PM
David, this is what works now:
Script Include:
var Group_and_CI_1 = Class.create();
Group_and_CI_1.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getallValues : function() {
var output;
var grp = this.getParameter("sysparm_grp");
var cmdb = this.getParameter("sysparm_ci");
gs.log('TESTING: grp is = ' + grp); //Added by Will
gs.log('TESTING: cmdb is = ' + cmdb); //Added by Will
var gr = new GlideRecord('u_m2m_groups_configuratio');
gr.addQuery('u_group.type', grp);
gr.addQuery('u_configuration_item', cmdb);
gr.query();
gs.log('TESTING: Result before IF is = ' + gr.output); //Added by Will
gs.log('TESTING Row Count is '+ gr.getRowCount()); //Added by Will
if(gr.next()) {
//output = gr.sys_id +" \n";
output = gr.u_group +" \n";
gs.log('TESTING: Result after IF is = ' + output); //Added by Will
}
gs.log('TESTING Result Before Output is '+ output); // Added by Will
return output ;
},
type: 'Group_and_CI_1'
});
Client:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('Group_and_CI_1');
ga.addParam('sysparm_name', 'getallValues');
ga.addParam('sysparm_ci', g_form.getValue('cmdb_ci'));
ga.addParam('sysparm_grp', '1512159ddbc5a300b6e69b3c8a96195d');
ga.getXML(callback);
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue('u_glide_list_areas_impacted', answer);
}
}
Client Script passed the cmdb_ci and the group type.
Results in the Group being added to the Change Request u_field.
Do you want full credit, you led me to the final, or just helpful. I'm cool either way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2019 10:22 AM
This was very insightful.
So the script include is suppose to return the group, the client script supplies the type and cmdb_ci. It appears as though the current script include is not expecting the "group type" it is expecting the group name, which is developed wrong.
The u_m2m table does have the CMDB, but did not have the type field, it had the Group Name as u_group. I just added the dot walk to the type on the table so I will attempt to adjust. The table and the script include were previously provided. Looks like I will have to adjust their work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2019 10:24 AM
Also, it still is not populating the u_field on the change request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2019 12:00 PM
David, this is what works now:
Script Include:
var Group_and_CI_1 = Class.create();
Group_and_CI_1.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getallValues : function() {
var output;
var grp = this.getParameter("sysparm_grp");
var cmdb = this.getParameter("sysparm_ci");
gs.log('TESTING: grp is = ' + grp); //Added by Will
gs.log('TESTING: cmdb is = ' + cmdb); //Added by Will
var gr = new GlideRecord('u_m2m_groups_configuratio');
gr.addQuery('u_group.type', grp);
gr.addQuery('u_configuration_item', cmdb);
gr.query();
gs.log('TESTING: Result before IF is = ' + gr.output); //Added by Will
gs.log('TESTING Row Count is '+ gr.getRowCount()); //Added by Will
if(gr.next()) {
//output = gr.sys_id +" \n";
output = gr.u_group +" \n";
gs.log('TESTING: Result after IF is = ' + output); //Added by Will
}
gs.log('TESTING Result Before Output is '+ output); // Added by Will
return output ;
},
type: 'Group_and_CI_1'
});
Client:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('Group_and_CI_1');
ga.addParam('sysparm_name', 'getallValues');
ga.addParam('sysparm_ci', g_form.getValue('cmdb_ci'));
ga.addParam('sysparm_grp', '1512159ddbc5a300b6e69b3c8a96195d');
ga.getXML(callback);
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue('u_glide_list_areas_impacted', answer);
}
}
Client Script passed the cmdb_ci and the group type.
Results in the Group being added to the Change Request u_field.
Do you want full credit, you led me to the final, or just helpful. I'm cool either way.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2019 12:15 PM
Nice! Glad that you got it working. I see you had to dot walk to u_group.type.
As for my answers mark them as you see fit. Helpful or correct. Just happy to help. Either way marking it as correct will help others with GlideAjax calls.
Cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2019 12:25 PM
Awesome collaboration David. Thank you!!!