Need help in UI page for 'g:ui_reference_multi' usage
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2023 03:13 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2023 06:21 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2023 02:13 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2023 02:37 AM
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)"/>
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2023 03:16 AM
@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.