- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2023 07:41 AM - edited ‎02-20-2023 04:21 AM
In the Catalog items i have a field name incident (
using the script inlcude what i select in the incident field --> that particular caller_ID should be seen in the callerid field.
but the caller_id of the incident is not coming. what is wrong with the script?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2023 01:28 AM
Script include :
var getUserUtils = Class.create();
getUserUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCaller: function() {
// Create Object to get Incident number and caller ID from incident
var users = [];
// get Incident sys Ids from client script
var incidentSysIDs = this.getParameter('sysparm_incidentSysIDs');
// glide record on incidnet table
var grINC = new GlideRecord('incident');
grINC.addEncodedQuery('sys_idIN' + incidentSysIDs); //query with incident sys id
grINC.query();
while (grINC.next()) {
var info ={
incident: '',
callerID: '',
// if you have a called field on catalog form as reference then use sysId
sysId:'',
};
//store values in users object
info.incident = grINC.getValue('number').toString();
info.callerID = grINC.getDisplayValue('caller_id').toString();
info.sysId = grINC.getValue('caller_id').toString();
users.push(info);
}
gs.log('getUserUtils:Information= ' + JSON.stringify(users));
return JSON.stringify(users);
},
Client Script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var incidents = g_form.getValue('incidents');
var gaINCUsers = new GlideAjax('getUserUtils'); // Glide Ajax
gaINCUsers.addParam('sysparm_incidentSysIDs', incidents); // variable values passed to script include
gaINCUsers.addParam('sysparm_name', 'getCaller'); // function name in script include
gaINCUsers.getXMLAnswer(callback);
function callback(answer) {
var results = JSON.parse(answer);
var storeValues =[];
for (var i = 0; i < results.length; i++) {
storeValues.push('Incident:' + results[i].incident + ' ' + 'Caller = ' + results[i].callerID );
}
g_form.setValue('fields', storeValues);
}
}
This will definitely work.
output :
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2023 12:09 AM - edited ‎02-20-2023 04:22 AM
@Vishal Birajdar its working fine .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2023 12:24 AM
Update the Client Script As below :
Client Script :
On Change of Variable - 'incidents'
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var incidents = g_form.getValue('incidents');
var gaINCUsers = new GlideAjax('getUserUtils'); // Glide Ajax
gaINCUsers.addParam('sysparm_incidentSysIDs', incidents); // variable values passed to script include
gaINCUsers.addParam('sysparm_name', 'getCaller'); // function name in script include
gaINCUsers.getXMLAnswer(callback);
function callback(answer) {
var results = JSON.parse(answer);
var storeValues;
for(var int i ;i<results.length ; i++){
storeValues = storeValues + 'Incident= ' + results[i].incident + ' ' + 'Caller = ' + results[i].callerID
}
g_form.setValue('fields',storeValues);
}
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2023 12:34 AM - edited ‎02-20-2023 04:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2023 01:28 AM
Script include :
var getUserUtils = Class.create();
getUserUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCaller: function() {
// Create Object to get Incident number and caller ID from incident
var users = [];
// get Incident sys Ids from client script
var incidentSysIDs = this.getParameter('sysparm_incidentSysIDs');
// glide record on incidnet table
var grINC = new GlideRecord('incident');
grINC.addEncodedQuery('sys_idIN' + incidentSysIDs); //query with incident sys id
grINC.query();
while (grINC.next()) {
var info ={
incident: '',
callerID: '',
// if you have a called field on catalog form as reference then use sysId
sysId:'',
};
//store values in users object
info.incident = grINC.getValue('number').toString();
info.callerID = grINC.getDisplayValue('caller_id').toString();
info.sysId = grINC.getValue('caller_id').toString();
users.push(info);
}
gs.log('getUserUtils:Information= ' + JSON.stringify(users));
return JSON.stringify(users);
},
Client Script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var incidents = g_form.getValue('incidents');
var gaINCUsers = new GlideAjax('getUserUtils'); // Glide Ajax
gaINCUsers.addParam('sysparm_incidentSysIDs', incidents); // variable values passed to script include
gaINCUsers.addParam('sysparm_name', 'getCaller'); // function name in script include
gaINCUsers.getXMLAnswer(callback);
function callback(answer) {
var results = JSON.parse(answer);
var storeValues =[];
for (var i = 0; i < results.length; i++) {
storeValues.push('Incident:' + results[i].incident + ' ' + 'Caller = ' + results[i].callerID );
}
g_form.setValue('fields', storeValues);
}
}
This will definitely work.
output :
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates