Change ui reference query

johnmcgrain
Kilo Explorer

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?

12 REPLIES 12

Hi Ankur,

I believe you, yet it somehow doesn't work for me. And my workaround by putting it in the additionalQual element brings me closer to the solution but results in the aforementioned problems (regarding the uncaught TypeError).

This is the HTML of the first reference field:

<g:ui_reference name="txt_caller" id="txt_caller" table="sys_user" query="active=true^u_domain=D40" displayValue="${jvar_disp_caller}" value="${jvar_caller_id}" onchange="getUserCI()" completer="AJAXTableCompleter" style="width:180px"/>

This is the HTML of the second reference field:

<g:ui_reference name="txt_laptop" id="txt_laptop" table="cmdb_ci" query="u_cmdb_ci_category=Laptop" style="width:180px"/>

And this is the client side code:

function getUserCI() {
	
	var jTxt_caller = gel('txt_caller').value;
	var jTxt_laptop = gel('lookup.txt_laptop');	
	
	if (jTxt_caller != '') {
		
		jTxt_laptop.setAttribute('onclick', "mousePositionSave(event); reflistOpen('jTxt_laptop', 'not', 'cmdb_ci', '', 'false', '', 'u_cmdb_ci_category=Laptop^assigned_to=" + jTxt_caller + "', '')");
	}
}

 

Kind regards,

Mike

Hi Mike,

please ensure you use the correct parameter with correct position

also use this while setting the query -> QUERY:

  UserLookUp.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'locationRecords', 'not', 'cmn_location', '', 'false','QUERY:active=true',           'sys_idIN" + locationArray+ "', '')");

Regards
Ankur

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

Hi Ankur,

I started with doing both. It didn't work. That's why I posted the code as I did. It's the result of a lot of trial and error.

Kind regards,

Mike

Mike322
Tera Contributor

Finally resolved the issue!

The answer was pretty close in hindsight and ended up changing the variable to assign in the setAttribute line:

 jTxt_laptop.setAttribute('onclick', "mousePositionSave(event); reflistOpen('txt_laptop', 'not', 'cmdb_ci', '', 'false', '', 'u_cmdb_ci_category=Laptop^assigned_to=" + jTxt_caller + "', '')");

The first parameter in the 'reflistOpen()' function refers to the HTML element. In my previous code example I was referring to the client-side's 'jTxt_laptop' variable. Since that variable doesn't exist at the HTML face of the functionality, it couldn't assign any value. The browser responded with the type error:

Uncaught TypeError: Cannot set property 'value' of null

Where I accidentally referred to 'jTxt_laptop' it was interpreted as 'null' as it didn't exist. The HTML element 'txt_laptop' is the actual element that stores the value so it all came together working fine when I put that in instead.

5 years old and still works. Modified to suit my needs and replaced the glidequery with glideajax etc.

Thanks Ankur!