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.

how to select users only part of that assignment group of that selected record in ui page

sinu2
Tera Expert

Hi,

 

i have created a ui action LIST CHOICE type and a UI page. 

 

In the list of records can selecte multiple records in the list view and click on the UI action so that ui page will open. Inside ui page i have created a reference field which refere to user table. 

 

Current condition

<g:ui_reference name="new_user_id" query="active=true^employee_numberISNOTEMPTY" id="new_user_id" table="sys_user" mandatory="true"/>

 

But i need to see users only users who are part of selected record assignment groups. How can i put this. 

 

Kindly help me

1 ACCEPTED SOLUTION

@sinu2 

try this

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

	<style>
		.required:before {
		content:"* ";
		color: red;
		}
	</style>
	
	<g:evaluate var="jvar_sysId" expression="RP.getWindowProperties().sysparm_id"/>

	<g:ui_form>
		<input type="hidden" name="selected_record_sysId" value="${sysparm_id}"/> 
		<p class="required">Please select user to assign selected records</p> 
		<g:ui_reference name="new_user_id" query="${jvar_users}" id="new_user_id" table="sys_user" mandatory="true^active=true"/>
		<br>
		</br>
		<br>
		</br>
		<g:dialog_buttons_ok_cancel ok="return validateForm()" cancel="return onCancel()"/> 
	</g:ui_form>	

	<g:evaluate var="jvar_users">
		var selected_record_sysId = jelly.jvar_sysId;
		gs.info("line number 24 group ids--"+selected_record_sysId);
		var groupIDS = [];
		var recordgroups = new GlideRecord('x_thimi_fin_srvc_request');
		recordgroups.addEncodedQuery("sys_idIN"+selected_record_sysId);
		recordgroups.query();
		while(recordgroups.next()){
		groupIDS.push(recordgroups.getValue(assignment_group));

		}

		var ug = new GlideRecord('sys_user_grmember');
		ug.addEncodedQuery("groupIN" + groupIDS);
		ug.query();
		var list = []; // create an array of user IDs
		while (ug.next()) {
		list.push(ug.getValue('user')); // add record's user to list as a member of that group
		}
		list.toString();
	</g:evaluate>

</j:jelly>
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

22 REPLIES 22

@sinu2 

Glad to know.

Please mark my response as correct and close the thread.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@sinu2 

Would you mind closing the thread by marking my response as correct?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

I have marked your response as solution accepted