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.

Need to filter for stockroom reference field

Atchamma D
Tera Contributor

Hi All,

 

On the form level I have one of the field called "stockroom" and referring to alm_stockroom table.

And I have one field on the form level that is "Requested for" based on this requested for field I need to filter the stockroom field with stockroom record == active AND requestor is a member of the stockroom assignment group field this condition.

 

Please any one provide me the input,

Thanks in advance,

Atchamma D

1 ACCEPTED SOLUTION

Hi @Atchamma D 

 

You can follow the below steps :

 

Step 1 : Create script include 

Name : stockRoomUtils

 

 

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

getStockroom : function(requested_for){

/*1. Declare the variables */
var result;
var groupArray =[];

/*2. get the groups which user is member of */
var grMem = new GlideRecord('sys_user_grmember');
grMem.addQuery('user',requested_for);
grMem.query();

while (grMem.next()){

	/*3. get the groups in array */
	groupArray.push(grMem.group.name);

}

/*4. set the result with query */
result = 'assignment_group.nameIN' + groupArray.toString();   //you can add your query here like for active  'active=true^assignment_group.nameIN' + groupArray.toString(); 

/*5. Return the result*/
return result;
},


    type: 'stockRoomUtils'
};

 

 

VishalBirajdar_1-1698232240826.png

 

 

Step 2 : on Stockroom variable write Advance reference qualifier

 

 

 

javascript: new stockRoomUtils().getStockroom(current.variables.requested_for);  // use your variable name

 

 

 

VishalBirajdar_0-1698232211101.png

 

 

Output : 

In my case Abel tutor is member of "App Engine Admins" assignment group & this group is added to stockroom

 

VishalBirajdar_2-1698232343988.png

 

VishalBirajdar_3-1698232388772.png

 

Hope this helps....!!!

 

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

5 REPLIES 5

Vishal Birajdar
Giga Sage

Hi @Atchamma D 

 

Is your requirement for catalog item or on Native UI form...??

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Hi @Vishal Birajdar 

 for catalog item 

Hi @Atchamma D 

 

You can follow the below steps :

 

Step 1 : Create script include 

Name : stockRoomUtils

 

 

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

getStockroom : function(requested_for){

/*1. Declare the variables */
var result;
var groupArray =[];

/*2. get the groups which user is member of */
var grMem = new GlideRecord('sys_user_grmember');
grMem.addQuery('user',requested_for);
grMem.query();

while (grMem.next()){

	/*3. get the groups in array */
	groupArray.push(grMem.group.name);

}

/*4. set the result with query */
result = 'assignment_group.nameIN' + groupArray.toString();   //you can add your query here like for active  'active=true^assignment_group.nameIN' + groupArray.toString(); 

/*5. Return the result*/
return result;
},


    type: 'stockRoomUtils'
};

 

 

VishalBirajdar_1-1698232240826.png

 

 

Step 2 : on Stockroom variable write Advance reference qualifier

 

 

 

javascript: new stockRoomUtils().getStockroom(current.variables.requested_for);  // use your variable name

 

 

 

VishalBirajdar_0-1698232211101.png

 

 

Output : 

In my case Abel tutor is member of "App Engine Admins" assignment group & this group is added to stockroom

 

VishalBirajdar_2-1698232343988.png

 

VishalBirajdar_3-1698232388772.png

 

Hope this helps....!!!

 

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Thanks @Vishal Birajdar its working!!!