How to make assigned_to field dependent on assignment group on a UI page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2017 08:56 PM
Hi All,
I am designing an UI page which consists of Assignment Group and Assigned To fields. I am struck at a point where in i want to make assigned to field dependent on assignment group. like after selecting assignment group and if i select assigned to field i should get only users in the group selected.
I have checked the community which provided solution to link assignment group and assigned to but could not fit it to my requirement. I have mentioned the code here. Please help. Thanks.
<?xml version="1.0" encoding="utf-8"?>
<j:jelly xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null" trim="false">
<script>https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<body ng-app="angularHelloWorldApp" ng-controller="MainController">
<table>
<div>
<tr>
<label>Assignment Group:</label>
<g:ui_reference onchange="setGroup(this)" name="group" id="group" table="sys_user_group" query="GOTOnameSTARTSWITHHelp" completer="AJAXTableCompleter" ng-model="group"/>
<br></br>
<label>Assigned To:</label>
<g:ui_reference onchange="setUser(this)" name="user" id="user" table="sys_user" query="sys_idIN${jvar_users}" completer="AJAXTableCompleter" ng-model="user"/>
<br></br>
</tr>
</div>
</table>
</body>
</j:jelly>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2017 08:31 AM
Hi Sangun,
Did you tried my suggestions from prvious post?
Thanks
Prashant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2017 05:36 AM
Hi Sangun,
The above solution works but one enhancement I did from my side:
1) I am making the 2nd reference lookup as editable false on form/body load and once user selects the group then in order to allow the user to lookup the users i am making the second reference as editable again.
This avoid/takes care of the following scenario
User does a lookup from user table first and then does group lookup. So here the onChange script will show only 2 users since filter query will be applied but since user is already populated in the reference field it will still show the older value and form can get submitted.
The things marked as BOLD are the extra additions to the script as compared to my earlier comment.So this script is the modified script which you can try
Script
HTML Section
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<html>
<body onload="makeReadonly()">
Group: <g:ui_reference name="group" id="group" table="sys_user_group" completer="AJAXTableCompleter" query="active=true" onchange="setUserFilter()"/>
Users: <g:ui_reference name="userRecords" id="userRecords" table="sys_user" completer="AJAXTableCompleter"/>
</body>
</html>
</j:jelly>
Client Script
function setUserFilter(){
var groupSysId = gel('group').value;
var UserLookUp = gel('lookup.userRecords');
var userArray = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", groupSysId);
gr.query();
while (gr.next()) {
userArray.push(gr.user.toString());
}
UserLookUp.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'userRecords', 'not', 'sys_user', '', 'false','QUERY:active=true', 'sys_idIN" + userArray+ "', '')");
// make this as editable so that user can select from lookup
var a = gel('sys_display.userRecords');
a.removeAttribute("disabled"); // removing the disabled attribute
var b = gel('lookup.userRecords');
b.removeAttribute("disabled"); // removing the disabled attribute
}
function makeReadonly(){
// make the second lookup as readonly on form/body load
var a= document.getElementById('sys_display.userRecords');
a.setAttribute('disabled','true');
var b=document.getElementById('lookup.userRecords');
b.setAttribute('disabled','true');
}
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2017 03:42 AM
Hi Sangun,
Any update on this? Can you mark my answer as correct, helpful and hit like if you were able to achieve your requirement. This helps in removing this question from unanswered list. Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2017 01:40 AM
Hi Sangun,
I have found a way to achieve this and I have developed the script and is working fine. it is restricting the users based on the assignment group.
Example:
Group A - member 1, member 2
Group B- member 3, member 4
When you select Group A in first lookup and then click on the lookup icon for users it will show only 2 members/users i.e. Member 1 and Member 2
Similar is for Group B.
Here is the script.
HTML Section
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
Group: <g:ui_reference name="group" id="group" table="sys_user_group" completer="AJAXTableCompleter" query="active=true" onchange="setUserFilter()"/>
Users: <g:ui_reference name="userRecords" id="userRecords" table="sys_user" completer="AJAXTableCompleter"/>
</j:jelly>
Client Script
function setUserFilter(){
var groupSysId = gel('group').value;
var UserLookUp = gel('lookup.userRecords');
var userArray = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", groupSysId);
gr.query();
while (gr.next()) {
userArray.push(gr.user.toString());
}
UserLookUp.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'userRecords', 'not', 'sys_user', '', 'false','QUERY:active=true', 'sys_idIN" + userArray+ "', '')");
}
Please let me know if any issue while implementing this.
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2019 02:45 AM
Hello Ankur ,
I have to same requirement , code above is working fine but user can still able to enter names which are not are part of that group by typing name.
Any idea how to stop this?
Thanks
Neeraj Sharma