Reference Qualifier on Lookup Select Box Variable

Blair5
Tera Guru

I've been looking through the WIKI/community and it seems like there is a bug with reference qualifiers on Lookup Select box variables. Does anyone know if there is a work around besides making the field a reference variable?

I have 3 variables on a form -- each dependent on the last. The first is a lookup select box and I'd like the second to be a lookup select box with a reference qualifier because setting it as a reference variable gives the same information as the third variable. I've tried only showing the columns I want (with attributes), but it still shows too much.

Is there another angle I can take? Building the list with a script? I only want to show unique values. Any ideas/help would be greatly appreciated because I think I've exhausted all the options I can think of. Thanks!

1 ACCEPTED SOLUTION

Kalaiarasan Pus
Giga Sage

Seems like we all have been trolled here Look up select supports reference qualifier but it's not simple as reference field..



Check the wiki page



http://wiki.servicenow.com/index.php?title=Variable_Types#Lookup_Select_Box



We need to use 'ref_qual_elements' attribute to get the updated reference working..


I am able to do the dynamic thing working after adding the attribute...



Sample demo:



Create 2 lookup select variable called 'located_at' and 'user' referring location and user table respectively.


Idea here is to display the user depending on the location selected...


In the user variable, define reference qual as javascript: 'location='+current.variables.located_at; and variable attribute as ref_qual_elements=located_at



This will make the variable to use the updated reference. Try this out and let me know if this works for you as well.



Note: I tried on Fuji instance.


View solution in original post

78 REPLIES 78

tltoulson
Kilo Sage

Hi Blair,



The approach I normally take here is to build the Choice List via a Client Script.   Basically I use GlideRecord to get a list of records that match my desired ref qual, remove all the existing options in the list, and then add the options from the GlideRecord.     Its a bit crude but it works.


Travis,



Could you give me an example of what this would look like?


Hi Blair,



Here is an example of an onLoad script you could use:



function onLoad() {


        g_form.clearOptions('fieldname'); // Removes all options


       


        var gr = new GlideRecord('table name');


        gr.addQuery('anotherFieldName', 'value'); // Setup the appropriate query here


        gr.query(function(rec) {


                  // Callback function is called once the GlideRecord is returned from the Server


                  while (rec.next()) {


                            g_form.addOption('fieldname', rec.sys_id, rec.getDisplayValue());


                  }


        });            


}



Obviously it will need some tweaking.   You need to change the field name, table name, and query.   You may need to change other things depending on your use case but this should provide a solid foundation.


Travis,



I appreciate your help. I will try this out and see how it works.



Thanks again!


Travis,



I understand that this client script adding the values on the client, so when the catalog item is submitted, the selections are no longer there and the variable appears as blank. I used your script and modified a bit -- is there a way to 'keep' the option selected in the variable?



function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading || newValue == '') {


  return;


  }



  g_form.clearOptions('role'); // Removes all options



  var gr = new GlideRecord('u_privileged_support_roles');


  gr.addQuery('u_platform', 'CONTAINS', newValue); // Setup the appropriate query here


  gr.query();


  while (gr.next()) {


  var typeOptions = g_form.getControl('role');


  var str = typeOptions.innerHTML;


  if(str.indexOf(gr.u_role_category)==-1){


  g_form.addOption('role', gr.sys_id, gr.u_role_category);


  }


  }


}