
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 07:09 AM
Hello SN community,
My script include isn't working. I'm trying to display incidents based on a caller off a custom table that's been extended from the incident table. Here is the catalog client script and the script include. So, on the record producer there is a variable (caller_id, - this is a reference field off the user table). The second variable is Incident Number (u_incident_number - a reference field to the incident table). What I want to happen, is for the manager to enter in a Caller's name in the field, then for the scripts to return the most recent incident for that Caller. The form's purpose is for agent call evaluations....so the manager will be reviewing calls real-time and will fill out the form. Hopefully, I can script this so as the manager enters the Caller name, then the most current incident will auto-populate for the manager. Since the agent evaluations are real-time, the manager won't have time to query the incident table themselves.
Is this possible?
Catalog client script:
Type is On change
Variable is caller_id
------------------------------------------------------------------------------------
function onChange(control, oldValue, newValue, isLoading) {
if (oldValue == newValue) {
return;
}
{
var call = g_form.getValue('caller_id');
var ga = new GlideAjax('FindCallerINC');
ga.addParam('sysparm_name','FindCallerINC');
ga.addParam('sysparm_call', call);
ga.getXML(FindCallerINCParse);
}
function FindCallerINC(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_incident_number', 'answer');
}
}
Script include:
----------------------------------------------------------------------------------------
var FindCallerINC = Class.create();
FindCallerINC.prototype = Object.extendsObject(AbstractAjaxProcessor, {
FindCallerINC: function() {
var cl = this.getParameter("sysparm_call");
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', cl);
gr.addQuery('active','true');
gr.query();
while(gr.next()){
var number = gr.number;
var answer = number;
}
return answer;
}
});
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 10:07 AM
Hi Lola,
Could you please provide the screenshots of what you have configured. Please make sure that you are using the below script and in the advance reference qualifier it is being called as javascript:FindCallerINC();. My bad, I overlooked the way var cl is defined in my last response. Please do modify like below and give it a try.
function FindCallerINC() {
var cl = current.variables.caller_id;
var answer;
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', cl);
gr.addQuery('active','true');
gr.orderBy('sys_created'); //This is an optional one. You may remove this line
gr.query();
while(gr.next()) {
if (answer.length > 0) {
//build a comma separated string of groups if there is more than one
answer +=(',' + gr.sys_id).toString();
}
else {
answer = gr.sys_id.toString();
}
return 'sys_idIN' + answer;
}
}
}
I hope this helps.Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 08:41 AM
Hi Lola,
Request you to try the below Script Include and let me know.
var FindCallerINC = Class.create();
FindCallerINC.prototype = Object.extendsObject(AbstractAjaxProcessor, {
FindCallerINC: function() {
var cl = this.getParameter("sysparm_call");
var answer;
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', cl);
gr.addQuery('active','true');
gr.orderBy('sys_created');
gr.query();
while(gr.next()) {
if (answer.length > 0) {
//build a comma separated string of groups if there is more than one
answer+ = (',' + gr.sys_id).toString();
}
else {
answer = gr.sys_id.toString();
}
}
return 'sys_idIN' + answer;
}
I hope this helps.Please mark correct/helpful based on impact

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 08:49 AM
Thanks for the reply! But, it's still not working. I used your script but after I add the caller name to the incident number field, the results are showing all incidents for all callers. My objective is to only return the most recent incident for the caller inputted in the caller field. Any other ideas here? Thanks in advance!
FindCallerINC.prototype = Object.extendsObject(AbstractAjaxProcessor, {
FindCallerINC: function() {
var cl = this.getParameter("sysparm_call");
var answer;
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', cl);
gr.addQuery('active','true');
gr.orderBy('sys_created');
gr.query();
while(gr.next()) {
if (answer.length > 0) {
//build a comma separated string of groups if there is more than one
answer +=(',' + gr.sys_id).toString();
}
else {
answer = gr.sys_id.toString();
}
return 'sys_idIN' + answer;
}
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 09:06 AM
Hi Lola,
Couple of things I would request you to implement or cross check.
1. Please ensure that the in the catalog item the variable 'caller_id' (on change of which you want to populate the incidents) is a Reference type of field which refers User (sys_user) table.
2. For your this requirement you do not have to write the onChange Client Script. Please inactive the client script and use the advance Reference qualifier. Modify the script include as below. Just replace all the existing code of the script include with the below one and save the script include by the name FindCallerINC. In the advance reference qualifier you need to call the script include as javascript:FindCallerINC(). If you face any problem implementing this part, please refer referred threads (particularly the first 1).
function FindCallerINC() {
var cl = this.getParameter("sysparm_call");
var answer;
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', cl);
gr.addQuery('active','true');
gr.orderBy('sys_created'); //This is an optional one. You may remove this line
gr.query();
while(gr.next()) {
if (answer.length > 0) {
//build a comma separated string of groups if there is more than one
answer +=(',' + gr.sys_id).toString();
}
else {
answer = gr.sys_id.toString();
}
return 'sys_idIN' + answer;
}
}
}
I have answered similar questions earlier, please refer the threads below:
1. Script Include Advanced Reference Qualifier help required
2. Service catalog lookup Select Box choice's validation based on a table fields.
I hope this helps.Please mark correct/helpful based on impact

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 10:01 AM
Hi Amlan,
Thank you for the quick reply! It did get me closer. Yes, the caller_id field is referencing the sys_user table. I copied your script to a script include and named it as you indicated. I also inactivated the catalog client script as you indicated.
Then, I updated the advanced reference qualifier on the incident number field to call javascript:FindCallerINC.
The result is that the incident number is a status incident number. For some reason, if the caller field is empty, populated, or changed to another caller; the incident number is the same one for all values in the caller field.
Any other ideas as to why the returned incident number is the same for all caller values?
Thanks in advance!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 10:07 AM
Hi Lola,
Could you please provide the screenshots of what you have configured. Please make sure that you are using the below script and in the advance reference qualifier it is being called as javascript:FindCallerINC();. My bad, I overlooked the way var cl is defined in my last response. Please do modify like below and give it a try.
function FindCallerINC() {
var cl = current.variables.caller_id;
var answer;
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', cl);
gr.addQuery('active','true');
gr.orderBy('sys_created'); //This is an optional one. You may remove this line
gr.query();
while(gr.next()) {
if (answer.length > 0) {
//build a comma separated string of groups if there is more than one
answer +=(',' + gr.sys_id).toString();
}
else {
answer = gr.sys_id.toString();
}
return 'sys_idIN' + answer;
}
}
}
I hope this helps.Please mark correct/helpful based on impact