Change ui reference query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2017 06:11 PM
Hi All,
I have a UI reference:
<g:ui_reference name="company" id="company" table="core_company"/>
I would like to be able to query for that companies location on another UI reference, e.g.
<g:ui_reference name="location" id="location" table="cmp_location" query="nameSTARTSWITH${company}"/>
Does anyone have thoughts on how to achieve this?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2017 02:15 AM
This post may help: Re: UI page dependent reference field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2017 01:49 AM
Hi John,
I have found a way to achieve this and I have developed the script and is working fine. it is restricting the locations based on the company selection
Example:
Company A - Location 1, Location 2
Company B - Location 3, Location 4
When you select Company A in first lookup and then click on the lookup icon for locations it will show only 2 location i.e. Location 1 and Location 2
Similar is for Company 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">
Company: <g:ui_reference name="company" id="company" table="core_company" completer="AJAXTableCompleter" query="active=true" onchange="setLocationFilter()"/>
Location: <g:ui_reference name="locationRecords" id="locationRecords" table="cmn_location"/>
</j:jelly>
Client Script
function setLocationFilter(){
var groupSysId = gel('company').value;
var UserLookUp = gel('lookup.locationRecords');
var locationArray = [];
var gr = new GlideRecord("cmn_location");
gr.addQuery("company", groupSysId);
gr.query();
while (gr.next()) {
locationArray.push(gr.sys_id.toString());
}
UserLookUp.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'locationRecords', 'not', 'cmn_location', '', 'false','QUERY:active=true', 'sys_idIN" + locationArray+ "', '')");
}
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
02-25-2021 06:05 AM
Hi Angkur,
I tried using your example and also the example you probably got your information from.
Alas none of it worked until I put the dynamic part of the query in the "" after where you put your query. After a bit of research I found out that this particular part is referred to as 'additionalQual'.
The part you put your query in is 'refQualElements'. The entire format of the function 'reflistOpen' is as follows:
function reflistOpen(target, elementName, refTableName, dependent, useQBE, refQualElements, additionalQual)
BUT... while my change did use the correct reference qualifier in my UI Page's reference fields, I cannot seem to actually select an item. I see the result list in the pop-up but when you click one of the records, the window remains stationary and only produces a console error:
Uncaught TypeError: Cannot set property 'value' of null
I haven't been able to resolve this yet. Does you or anyone else have an idea? It would be greatly appreciated.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2021 06:43 AM