Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to Use Reference Qualifier for a Lookup Select Box

chris_choi
Giga Contributor

Hello,

I am trying to populate a Lookup Select Box with the list of Mobile Phone #'s that is associated with a requested_for on an requested item form.

In the Past we have used the following Script Include called filterDevices on a reference qualifier line for a reference field.

function filterDevices() {

  var answer = ' ';

  var rf = current.variables.requested_for;

  var usr = new GlideRecord('cmdb_ci_comm');    

  usr.addQuery('assigned_to',rf);

  usr.query();

  while (usr.next()) {

      if (answer.length > 0) {

          answer += (',' + usr.sys_id);

          }

      else {

          answer = usr.sys_id;

          }

      }

  return 'sys_idIN' + answer;

  }

We have tried using this script include on the Lookup Select Box, but we do not get any results. We also tried variations of "assigned_to=current.variables.requested_for" and get 0 results. but when we tried "assigned_to=javascript:gs.getUserID()" it does return all mobile phones for the person logged in.

If anyone can point out if this is a syntax issue or if we are going about this incorrectly, it would much appreciated. Thanks

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
9 REPLIES 9

Thanks for the response, I have tried what you suggested and it didn't seem to return anything.


I would do some debugging: Is rf populated with something sensible?



Also: here's an easier way to build a comma separated list.



function filterDevices() {


  var answer = [];


  var rf = current.variables.requested_for;


  var usr = new GlideRecord('cmdb_ci_comm');  


  usr.addQuery('assigned_to',rf);


  usr.query();


  while (usr.next()) {


          answer.push(usr.sys_id);


  }


  return 'sys_idIN' + answer.join(',');


}


rf is getting a reference field to the User table we have.



Our script include works for normal reference fields, where we use it as a reference qualifier. It just doesnt seem to work with Lookup Select Box. I will try the script include you have suggested to see if that fairs any better.


Gurpreet07
Mega Sage

As Pradeepprovided of a link to a thread. You also need to add attribute 'ref_qual_elements' in addition to reference qual.


Hey Gurpreet,



I reread the links that Pradeep provided and it made a lot more sense after mentioning ref_qual_elements.



The syntax that ended up working was:


Reference qual: javascript: 'assigned_to='+current.variables.requested_for;


Variable attributes: ref_qual_elements=requested_for



I read the Wiki page a handful of times and it wasnt apparent to me that this is what needed to happen.



Thanks for your suggestions.