Ankur Bawiskar
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  ||  10x 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.

@Divya P 

can you try this?

var YearLookUp = gel('lookup.multi'); //document.getElementById("multi") //gel('lookup.multi');

YearLookUp.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'multi', 'not', 'sys_choice', '', 'false','QUERY:inactive=false','sys_idIN" + userArray+ "', '')");

 

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

Divya P
Tera Contributor

@Ankur Bawiskar I am not using  g:ui_referene ui macro since I am using  g:ui_reference_multi ui macro below is not working 

 

YearLookUp.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'multi', 'not', 'sys_choice', '', 'false','QUERY:inactive=false','sys_idIN" + userArray+ "', '')");

Tushar
Kilo Sage

 I hope this helps - 

 

<g:ui_reference_multi id="multi" name="multi" table="sys_choice" reference="sys_choice" columns="label" onchange="onMonthChange()"/>

 

Client Script -

 

function onMonthChange() {
  var answer = g_form.getValue('your_other_field'); // Replace 'your_other_field' with the actual field name that holds the value to be used for the query
  var mnthsArr = JSON.parse(answer);

  var userArray = [];

  // Query the 'sys_choice' table on the client-side to get the sys_ids for the months based on the selected date
  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());
  }

  // Get the reference field element
  var referenceField = document.getElementById('multi');

  // Set the reference attribute on the g:ui_reference_multi macro with the dynamic query
  referenceField.setAttribute('reference', 'sys_choice'); // Set the table name for the reference field
  referenceField.setAttribute('query', "active=true^sys_idIN" + userArray.join(',')); // Set the dynamic query based on the selected date
}

 

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