Advanced Reference Qualifier for Empty list.

Gabriel Prieto
Kilo Contributor

Good Night everyone, I get stuck in this task. I need to do this with advanced reference qualifier. The first part, to show only the computers, I used this code: javascript:"assigned_to="+current.variables.requester. But the second part is trick for me.

Further logic to be implemented requires that the reference field 'Enter the Computer Name(s), sometimes called Workstation ID' must.

Show only computers assigned to the user selected as requester

In case the requester is empty will show an EMPTY list.

Create a new advanced reference qualifier for the 'user_pc' variable that will be able to use the 'recipient' 

 

2 REPLIES 2

Xavier Cordero
Kilo Sage

Hello Gabriel,

I'll assume that you are referencing computers within the alm_asset table?

Create a script include called computerrefqual (the names are important as they much match within your reference field and the script include).

Add the following script within the script include:

var computerrefqual = Class.create();
computerrefqual.prototype = {
    initialize: function() {
    },
	assignedComputers: function(){
		//Get Computer sys_id.
		var computer = new GlideRecord('cmdb_model_category');
		computer.get('name','Computer');
		var gr = new GlideRecord('alm_asset');
		gr.addQuery('assigned_to',String(current.variables.recipient));
		gr.addQuery('model_category',computer.getValue('sys_id'));
		gr.query();
		var computerArray = [];
		while(gr.next()){
			computerArray.push(gr.getValue('sys_id'));
		}
		return 'sys_idIN' + computerArray.join(',');
	},
    type: 'computerrefqual'
};

Then, in the reference qualifier for the field, select advanced, and within the text box type:

javascript: new computerrefqual().assignedComputers();

Hi Xavier, thank you for your reply, but actually my reference table is cmdb_ci_computer