Need help in UI page for 'g:ui_reference_multi' usage

Divya P
Tera Contributor

I am trying to set the dynamic 'query' for a reference field (g:ui_reference_multi).
The query is set based on the value of the other field but I can't get it to work.

HTML Script:

Initially I have set the Query as below :


<g:ui_reference_multi id="multi" name="multi" table="sys_choice" query="name=u_hiring_plan_availability_hours^element=u_month" coloumns="label" onChange="onMonthChange(e)"/>

 

Client Script:

I am trying to show Months based on the year selected :

 

function getMonths(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var mnthsArr = JSON.parse(answer);
alert(mnthsArr);

var userArray = [];

//all the members of the selected group
var gmAud = new GlideRecord('sys_choice');
gmAud.addQuery('name', 'u_hiring_plan_availability_hours');
gmAud.addQuery('element', 'u_month');
gmAud.addQuery('value', mnthsArr[0]);
gmAud.query();
while (gmAud.next()) {
if (userArray.indexOf(gmAud.sys_id.toString()) == -1)
userArray.push(gmAud.sys_id.toString());
}
alert(userArray.toString());
var YearLookUp = gel('multi'); //document.getElementById("multi") //gel('lookup.multi');
YearLookUp.setAttribute('query','sys_idSTARTSWITHb8a29bf8db65fc109f9b6f8bd3961985');

}

}

 

Can anyone help me to set the query in client script based on change of other field

7 REPLIES 7

Tushar
Kilo Sage
Kilo Sage

Hi @Divya P 

 

following script should help -

 

<g:ui_reference_multi id="multi" name="multi" table="sys_choice" query="name=u_hiring_plan_availability_hours^element=u_month" columns="label" onChange="onMonthChange(event)"/>

 

function onMonthChange() {
  var monthValue = gel('monthField').value; // Assuming the ID of the Month field is "monthField"
  var yearLookUp = gel('yearField');
  yearLookUp.setAttribute('query', 'name=u_hiring_plan_availability_hours^element=u_month^value=' + monthValue);
}

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar

 

Divya P
Tera Contributor

Hi @Tushar  ,

 

Actually I wanted to change the query for below element

<g:ui_reference_multi id="multi" name="multi" table="sys_choice" query="name=u_hiring_plan_availability_hours^element=u_month" columns="label" onChange="onMonthChange(event)"/>

 

I tried using setAttribute but it didnt work . It is setting the query but the filter is not applied when I click on the the field.

Ankur Bawiskar
Tera Patron
Tera Patron

@Divya P 

can you try setting the name attribute with the filter condition?

<g:ui_reference_multi id="multi" name="multi" table="sys_choice" name="name=u_hiring_plan_availability_hours^element=u_month" query="name=u_hiring_plan_availability_hours^element=u_month" coloumns="label" onChange="onMonthChange(e)"/>

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

Divya P
Tera Contributor

@Ankur Bawiskar Nope didnt work.

 

Could you please help me set the filter in the client script.

Depending on the year user choose, I can obtain a list of all the sys_ids for the months that apply to that year. I am unable to set the filter in the client script, though.