- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 06:30 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 06:24 AM
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>
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 02:29 AM
you are querying sys_user_grmember in UI page but you have sys_ids of the record and not group
so you query those records of your table; get the group sysId and then query sys_user_grmember
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 02:33 AM
Since my ui action is cline callable , can i glide in UI action to get the group sys_id's?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 02:36 AM
Hi Ankur,
Any high level code so that i can insert in my ui page?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 02:58 AM
you can do GlideRecord in UI action even if it's client callable but you need to query 2 tables
1 is the current table to get group sysId and then sys_user_grmember to get the users
store all the users in array and pass that array to UI page and then set the query there
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 03:18 AM
Hi Ankur,
I have glided group assignment group sys_id's in my ui page HTML. Nut its not working any mistake in my script?
<?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: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="active=true^employee_numberISNOTEMPTY" id="new_user_id" table="sys_user" mandatory="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 groupIDS =[];
var recordgroups = new GlideRecord('x_thimi_fin_srvc_ar_request');
recordgroups.addEncodedQuery("sys_idIN"+selected_record_sysId);
recordgroups.query();
while(recordgroups.next()){
groupIDS.push(recordgroups.getValue(assignment_group));
gs.info('test line 31 group sysIDS--'+groupIDS);
var ug = new GlideRecord('sys_user_grmember');
ug..addEncodedQuery("sys_idIN"+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
}
gs.info('print list of users==='+list);
var users = list.join(','); // create comma separated values
return users;
}
</g:evaluate>
</j:jelly>