How to make one ui_reference field dependent on another ui_reference in a UI Page

agulati
Kilo Expert

I have 2 UI reference fields in a UI Page

 

- Assigned To

- Assignment Group

 

I want to show list of assignment groups based on assigned to selection.

 

Is there a way to do that in a UI Page? Is there a way to call a custom javascript that does this?

 

Thanks

1 ACCEPTED SOLUTION

marcguy
ServiceNow Employee
ServiceNow Employee

Good point it says on the wiki that since calgary, you can put a reference qualifier



This tag adds a reference to a page that can be referenced by a Processing Script. The following example creates a reference defined by name, id, and table parameters in the tag:



<g:ui_reference name="QUERY:active=true^roles=itil" id="assigned_to" table="sys_user" />


Then in the Processing Script, reference the name field like this:



newTask.assigned_to = request.getParameter("QUERY:active=true^roles=itil");


Beginning with the Calgary release, this tag has been enhanced to allow you to specify a reference qualifier, so that the "name" attribute can be unique. The following example creates a reference defined by name, id, and table parameters in the tag. Note: the "columns" attribute only applies to the auto-completer.



<g:ui_reference name="parent_id" id="parent_id" table="pm_project" query="active=true" completer="AJAXTableCompleter"  columns="project_manager;short_description"/>

View solution in original post

9 REPLIES 9

mike_thompson
Kilo Explorer

I was wondering if you were able to figure out how to use the reference qualifiers that were listed on the wiki to do this? I had just setup a ui page that I have two reference fields that are custom tables. On each table I have Key value so it would be easy to link the two together, but im at a lose as to how to get that to work correctly.



@ Michael



I was not able to get 2 reference control dependent on one another but used first control as reference and second as select box and was able to get that working.



-AMan


Community Alums
Not applicable

Hello @ Aman and @ Michael



This can be done by overwriting the onclick attribute of the "lookup.second_reference_field_name" of your second reference field. Within it, the key part that needs to be changed is the 7th parameter of the reftlistOpen(). Below is an example the one I have tried in IE, Chrome and Firefox without issues.



I hope it helps!      



function setFilterOverDependentReferenceField(){


  var firstReferenceFieldSysId = gel('first_reference_field').value;


  var secondReferenceFieldLookUp = gel('lookup.second_reference_field');


  secondReferenceFieldLookUp.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'second_reference_field', 'not', 'your_table_to_query', '', 'false','QUERY:active=true', 'u_reference_to_first_field=" + firstReferenceFieldSysId + "', '')");


}


I tried implementing something like this. While the pop-up reference list gets filtered, the autocomplete suggestions only work the first time.   
Example:  A value is selected in the firstReferenceField and secondReferenceField is filtered.    Select a value in the secondReferenceField.   
Now make another selection in the firstReferenceField. The filter changes for the secondReferenceField, but the autocomplete will only filter the record using the previous filter while the popup list will use the correct filter.

agulati
Kilo Expert

Hi All,



I have implemented the Incident Re-Assign Feature and uploaded on Share Site.



https://share.servicenow.com/app.do#/detailV2/bb0349072bf265004a1e976be8da159a/overview



Sharing the link as this might be helpful to others as well.



Thanks