Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Advanced reference qualifier using script include

DB1
Tera Contributor

Hello all,

I have a custom table - u_m2m_sys_user_cmdb_ci_service with 3 fields - User(sys_user), CI 1(u_cmdb_ci_service) and CI 2 (u_dev_prod_ci_secondary)

 

I need to create a variable on a catalog item to reference this table. However I need to query the table based on the logged in user and get to display the list to show up the value from 1 particular field from CI 1 (u_cmdb_ci_service.u_application_name)

 

I need help to achieve the same.

Below is the Script Include I am trying to build

var CRFNonUserShowappname = Class.create();
CRFNonUserShowappname.prototype = {
	initialize: function() {
	},

	getCIIDs: function(a){
		var usersList = [];
		var user = gs.getUserID();
		var gruser_list = new GlideRecord('u_m2m_sys_user_cmdb_ci_service');
		gruser_list.addQuery('sys_user',user);
		gruser_list.query();
		var results = [];
		while(gruser_list.next())
		{
			//usersList.push(gruser_list.getUniqueValue());
			var list = gruser_list.getDisplayValue('u_cmdb_ci_service.u_application_name');
		}

		return list;

	},

	type: 'CRFNonUserShowappname'
};

 

@Ankur Bawiskar @Sandeep Rajput @AnveshKumar M @Peter Bodelier 

12 REPLIES 12

Actually there is no User table reference at all on the catalog item

 

Wybren1
Tera Guru

If it's a variable within a catalog item it's called client sided, I'm guessing it should be a GlideAjax?

Other then this being commented and will not fill the array ofcourse:

//usersList.push(gruser_list.getUniqueValue());

 
Also your not filling the list correctly at the moment

getCIIDs: function(a){
		var usersCmdbCIList = [];

		var grUserCmdbCI= new GlideRecord('u_m2m_sys_user_cmdb_ci_service');
		grUserCmdbCI.addQuery('sys_user', gs.getUserID());
		grUserCmdbCI.query();

		while(grUserCmdbCI.next()) {
			usersCmdbCIList.push(grUserCmdbCI.getUniqueValue());
			//usersCmdbCIList.push(grUserCmdbCI.getDisplayValue('u_cmdb_ci_service.u_application_name'));

			//Your not pushing it so it will only take the last of the query
			//var list = gruser_list.getDisplayValue('u_cmdb_ci_service.u_application_name');
		}

		return usersCmdbCIList;

	},

 

DB1
Tera Contributor

I need to display the Application names though. How to do it?

Wybren1
Tera Guru

Use the one that commented out:

//usersCmdbCIList.push(grUserCmdbCI.getDisplayValue('u_cmdb_ci_service.u_application_name'));

DB1
Tera Contributor

Ok thank you, should I call the script include on Ref qualifier as below?

javascript: new CRFAddextusersshowCIList().getCIIDs(current.sys_user)