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

Sandeep132
Kilo Sage

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>

13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sangun,



Any update on this. Were you able to achieve the requirement?



if yes then please mark the answer as correct also mark helpful and hit like. This helps in closing the thread for the question and also helps other to find the answers quickly.



Thanks in advance.


Regards


Ankur


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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sangun,



Any update on this question?



Can you mark my answer as correct and helpful if you are able to achieve your requirement. This helps in removing this question from unanswered list.


Thanks in advance.



Regards


Ankur


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

Thanks Ankur



I tried using the code but I couldn't make it work. Would you know what am I missing here? Thanks



<g:ui_reference class="col-xs-12" name="channel" id="channel" table="u_cmdb_ci_service_channel" query="u_active=true"   onchange="setChannelFilter" />



<g:ui_reference name="bus_svc" id="bus_svc" table="u_cmdb_ci_service_business" completer="AJAXTableCompleter"/>



function setChannelFilter(){



var busSvcLkp = gel('lookup.bus_svc');



  busSvcLkp.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'bus_svc', 'not', 'u_cmdb_ci_service_business', '', 'false','QUERY:u_active=false','sys_class_nameINSTANCEOFcmdb_ci_service^u_parent_m2m=bde6a5abd5b90500aa69448450c55629', '')");


}


Hi Regina,



Your code seems fine. but one thing I found is it's a reference field so the query will have to be executed against the sys_id column. So do this below.



Query table "u_cmdb_ci_service_business" and have addQuery of sys_class_name and get the sys_id of those records. put that into array and give that array and check it once. Not sure how much this array will hold, but this you can try.



Here is the updated script:



<g:ui_reference class="col-xs-12" name="channel" id="channel" table="u_cmdb_ci_service_channel" query="u_active=true"   onchange="setChannelFilter" />



<g:ui_reference name="bus_svc" id="bus_svc" table="u_cmdb_ci_service_business" completer="AJAXTableCompleter"/>



function setChannelFilter(){



var busSvcLkp = gel('lookup.bus_svc');


var sysIdArray = [];



var gr = new GlideRecord('u_cmdb_ci_service_business');


gr.addEncodedQuery('sys_class_nameINSTANCEOFcmdb_ci_service^u_parent_m2m=bde6a5abd5b90500aa69448450c55629');


gr.query();


while(gr.next()){


sysIdArray.push(gr.sys_id.toString());


}


 


busSvcLkp.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'bus_svc', 'not', 'u_cmdb_ci_service_business', '', 'false','QUERY:active=true',         'sys_idIN" + sysIdArray+ "', '')");


}



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


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