How to apply dynamic filter to reference field in UI Page.

Abhijit4
Mega Sage

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.

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Rajesh Kannan G
ServiceNow Employee

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

View solution in original post

8 REPLIES 8

Ankush Jangle1
Kilo Guru

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

 

Shubham Bongulw
Giga Guru

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
    FieldDescription
    LabelEnter a descriptive name for the dynamic filter option.
    ScriptEnter 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 typeSelect Reference.
    Referenced tableSelect the table to which this dynamic filter option applies.
    OrderEnter a number to designate the placement of this dynamic filter option in the filter option choice list.
    RolesSelect the role a user must have to see this option.
    ActiveEnable or disable the option.
    Reference scriptOptional. 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 filterSelect this option to display the dynamic filter option as a filter breadcrumb.
    Available for defaultSelect this option to allow dynamic filter option to be a default in a dictionary entry.
    Available for ref qualSelect 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-

https://community.servicenow.com/community?id=community_question&sys_id=a71b83eddb5cdbc01dcaf3231f96...

Please mark helpful or correct if it helps!!1

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.