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

You need to return a query in a reference qualifier, so it's like

 

example:
javascript: "sys_idIN" + new CRFAddextusersshowCIList().getCIIDs(gs.getUserID());

 


Some examples:
https://docs.servicenow.com/en-US/bundle/vancouver-platform-administration/page/script/server-script...

DB1
Tera Contributor

I get the expected result when I tried from Background

var usersCmdbCIList = [];
var grUserCmdbCI= new GlideRecord('u_m2m_sys_user_cmdb_ci_service');
grUserCmdbCI.addQuery('sys_user','8d9b33fa4718919075211711e36d43c3');
grUserCmdbCI.query();
 
while(grUserCmdbCI.next()) {
//usersCmdbCIList.push(grUserCmdbCI.getUniqueValue());
//var userCI = usersCmdbCIList.push(grUserCmdbCI.getDisplayValue('u_cmdb_ci_service.u_application_name'));
                        gs.print(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');
}

 

How to use the same in Script include. Can someone please help

@Ankur Bawiskar @Sandeep Rajput @Peter Bodelier @Danish Bhairag2 

Hi @DB1 

 

You are getting the results because you can print the display value of a reference field.
Question is, do you need the u_m2m_sys_user_cmdb_ci_service records to be referenced in your variable, or the u_application_name table?


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.