How to clear value of g:ui_reference box in UI Page when user select different option?

Dennis10
Giga Contributor

Hi guys,

I have the following script:

HTML:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<table>
		<tr>
			<td >Source</td>
			<td><g:ui_reference id="source" name="source" table="itfm_cost_model" completer="AJAXTableCompleter" query="active=true" onChange="setUserFilter()" /></td>
		</tr>
		<tr>
			<td>Target</td>
			<td><g:ui_reference id="target" name="target" table="itfm_cost_model" completer="AJAXTableCompleter"/></td>
		</tr>
	</table>

</j:jelly>

Client Script:

function setUserFilter() {
document.getElementById('sys_display.target').value = '';
document.getElementById('target').value = '';
	var sysIDSource = gel('source').value;
	var UserLookUp = gel('lookup.target');
	var array = [];
	var gr = new GlideRecord("itfm_cost_model");
	gr.addQuery("sys_id", "!=", sysIDSource);
	//gr.addQuery('company.name', 'ACME Germany');
	gr.query();
	while(gr.next()) {
		array.push(gr.sys_id.toString());
	}
	UserLookUp.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'target', 'not', 'itfm_cost_model', '', 'false','QUERY:active=true', 'sys_idIN" + array+ "', '')");
}

I have tried with lines 2 and 3 in Client Script but it does not work. I need when user select different option in "Source", the "Target" field is cleared.

 

Thanks!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please check this

How to clear value of g:ui_reference box in UI Page when user select different option?

Regards
Ankur

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

View solution in original post

6 REPLIES 6

H @Ankur Bawiskar 
I tried the same. But I am selecting the option nothing is coming. It is clearing the value without changing the option.

Hi Ankur,

can i anyhow get the number of records that's loaded in g:ui_reference field.

any help appreciated.