- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2020 11:44 PM
Hi Everyone,
I have requirement to apply dynamic filter on reference field in UI Page.
I have managed to access that variable value in client script of that UI Page but I am not sure how to access that value and apply dyanmic filte to reference field,
Client script :
var ParsedURL=document.referrer.parseQuery();// to take parameters from parent url
if(parsedURL['sys_id']){
var sys_id=decodeURI(parsedURL['sys_id']
}
HTML
<g:ui_reference id='referenceTest' table='module' />
Here I want to add query attribute and want to include dynamic filter with sys_id variable.
Something like,
<g:ui_reference id='referenceTest' table='module' query='Number='+sys_id />
or
<g:ui_reference id='referenceTest' table='module' query='Number='+${sys_id} />
What is the correct way to use client script variable in HTML and apply dynamic filter?
Thanks in advance.
Regards,
Abhijit
ServiceNow MVP
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 01:45 AM
Hi,
If you only want the referer URL you can 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">
<g:evaluate jelly="true">
var referrer = GlideTransaction.get().getRequest().getHeader("Referer");
var query = "active=true";
if(!gs.nil(referrer)) {
var url = new GlideURL(referrer);
if(url)
query = query+"^kb_knowledge_base=" + url.get('sys_id');
}
query;
</g:evaluate>
<span>Query : $[query]</span>
</j:jelly>
Explanation: Fetch referer from request header, parse it using GlideURL, read referer url parameter using GlideURL.get to create your query. Now you can pass the query to g_uireference.
Regards,
Rajesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2020 11:53 PM
Hello,
In reference field you can apply the filter
<g:ui_reference name="QUERY:active=true^roles=itil" id="assigned_to" table="sys_user" />
Then in the Processing Script, you reference that name field like this:
newTask.assigned_to = request.getParameter("QUERY:active=true^roles=itil");
Mark it helpful/Correct if it helps you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2020 11:57 PM
Hi cody giant,
Procedure-
- Create a scripted filter as a client-callable script include or business rule.
- Navigate to System Definition > Dynamic Filter Options.
- Click New.
- Complete the form.
Dynamic filter options Field Description Label Enter a descriptive name for the dynamic filter option. Script Enter the name of the function you created, JavaScript (no script include needed), or the complete script include/business rule call, such as new GlobalCanvasUtil().refQualPaTabs()
.Field type Select Reference. Referenced table Select the table to which this dynamic filter option applies. Order Enter a number to designate the placement of this dynamic filter option in the filter option choice list. Roles Select the role a user must have to see this option. Active Enable or disable the option. Reference script Optional. Select the client-callable script include or business rule you created for the scripted filter. If the Script field contains JavaScript, an encoded query, or the entire script include/business rule reference, this field can be empty. Available for filter Select this option to display the dynamic filter option as a filter breadcrumb. Available for default Select this option to allow dynamic filter option to be a default in a dictionary entry. Available for ref qual Select this option to allow dynamic filter option to be selected as a dynamic reference qualifier. - Click Submit.
Also for the correct way to use client script variable in HTML please refer below-
Please mark helpful or correct if it helps!!1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 12:08 AM
you can get the value from the 1st <g:ui_reference> and then set 2nd tag query through client script of UI page
sharing few links which should help you;
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
07-06-2020 01:20 AM
Thanks Ankur,
I am trying few ways out here but somehow it is not working,
<g:ui_reference id="jiraNumber" table="u_nowjira" />
<script>
var releaseSysId='';
var parsedURL = document.referrer.parseQuery();
if (parsedURL['sys_id']) {
releaseSysId = decodeURI(parsedURL['sys_id']);
}
alert(releaseSysId);
gel('jiraNumber').setAttribute('name','QUERY:u_nowrelease'+releaseSysId);
</script>
the last line in the script is not setting that attribute to the element, in the console I see an error "Cannot read property attribute of null"
Any help would be appreciated.
Thanks.
Regards,
Abhijit
ServiceNow MVP