how to populate list of incidents created by an user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 04:25 AM
Hi all,
I have created some variables into catalog item, in those incident list will be one which is of list collector type. I have a requirement that, need to display all the incident numbers which are created by a particular user.
More clear when ever I change the requested_for, that particular user incidents should display.
Can anyone help with to do it.
Thanks in advance,
Sweety.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 04:53 AM
Hi sweety
You can add Reference qualifier to the incident variable.
javascript : 'caller_id='+current.variables.requested_for;
Modify variable names accordingly.
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 04:56 AM
Hi,
You need to use GlideAjax calls for this.
Create a catalog client script (on change - requested for) and make a AJAX call by sending the requested for user info to server side.
Now create a script include with function that checks gets the active incidents assigned to the user (requested for) and return it to the client side.
Now again on the client script you can display the returned incident numbers to your list collector.
Mark this as Helpful/Correct, if Applicable.
Regards,
Sourabh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 05:32 AM
Try something like this (just adjust the field names according to your set up)
Client script (on change of the requested for):
function onChange(control, oldValue, newValue, isLoading) {
var userID = g_form.getValue('requested_for');
if(userID) {
var incidentsAJAX = new GlideAjax('CatalogUtils');
incidentsAJAX.addParam('sysparm_name', 'listIncidents');
incidentsAJAX.addParam('sysparm_userID', userID);
incidentsAJAX.getXMLAnswer(populateIncidents);
}
else {
g_form.clearValue('example_list_collector');
}
function populateIncidents(answer) {
var incidentsList = JSON.parse(answer);
g_form.setValue('example_list_collector',incidentsList.join());
}
}
Script include (client callable):
var CatalogUtils = Class.create();
CatalogUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
listIncidents: function() {
var userID = this.getParameter('sysparm_userID');
var incList = [];
var incGR = new GlideRecord('incident');
incGR.addQuery('caller_id', userID);
incGR.query();
while (incGR.next()) {
incList.push(incGR.getUniqueValue());
}
return JSON.stringify(incList);
},
type: 'CatalogUtils'
});
And it will look like this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 10:30 AM
Hey Jan,
It's really helpful, but I can't able to get the expected result. Can you please check it let me know if there will be any corrections.
Client script:
function onChange(control, oldValue, newValue, isLoading) {
var userID = g_form.getValue('requested_for');
if (userID) {
var inc = new GlideAjax('listofincidents');
inc.addParam('sysparm_name', 'incidentslist');
inc.addParam('sysparm_userID', userID);
inc.getXMLAnswer(populateIncidents);
} else {
g_form.clearValue('incidents_list');
}
function populateIncidents(answer) {
var incsList = JSON.parse(answer);
g_form.setValue('incidents_list', incsList.join());
}
}
Script include:
var listofincidents = Class.create();
listofincidents.prototype = Object.extendsObject(AbstractAjaxProcessor, {
incidentslist: function() {
var user = this.getParameter('sysparm_userID');
var incList = [];
var incGR = new GlideRecord('incident');
incGR.addQuery('caller_id', user);
incGR.query();
while (incGR.next()) {
incList.push(incGR.getUniqueValue());
}
return JSON.stringify(incList);
},
type: 'listofincidents'
});