how to populate list of incidents created by an user

Sweety11
Kilo Contributor

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.

5 REPLIES 5

Voona Rohila
Kilo Patron
Kilo Patron

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

Sourabh26
Giga Guru

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

Jan Cernocky
Tera Guru

Try something like this (just adjust the field names according to your set up)

Client script (on change of the requested for):

find_real_file.png

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):

find_real_file.png

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

find_real_file.png

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'
});