How can I set a service catalog variable's reference qualifier with a service catalog script?

Stephen W_
Giga Guru

I have a variable set for use with Service Catalog items.

For this requirement, I cannot hard-code most of the the field attributes, they are dynamically defined.

 

As such, I need an onLoad() script that runs and displays/hides each of these fields and sets up their reference qualifiers..     To make this work, I need to be able to set the reference qualifier for each variable from this script.

 

How can I access this attribute?

 

Thanks,

-Stephen

1 ACCEPTED SOLUTION

Stephen W_
Giga Guru

The solution for this question was a combination of Srikanth's suggestion and something I found elsewhere.


(apologies if there are any mistakes here, I ended up going another route and don't have this exact code anymore)




Catalog Client Script:


OnLoad(){


var scVarElement = {};


var varMap = gel('variable_map');


var items = varMap.getElementsByTagName("item");



//This is the only way I found to get the sys_id for the item_option_new record.


for (var i = 0; i < items.length; i++) {


  var item = items.item(i);


  var name = item.getAttribute('qname');


  var id = item.id;


    scVarElement = {name:name,id:id,refqualifier:"whateverencodedqueryyouwant"};


}



//Now call an include script method with AJAX


var ga = new GlideAjax('ScItemIntfTypes');


  ga.addParam('sysparm_name','setQuestions');


  ga.addParam('sysparm_sc_options', scVarElement);


  ga.getXML();


}



Script Include:


setQuestions: function() {


  var grScOptions = new GlideRecord('item_option_new');



  var scQuestion = this.getParameter('sysparm_sc_options');


  if (grScOptions.get(scQuestion.id)){


      grScOptions.reference_qual = scQuestion.refqualifier;


      grScOptions.update();


  }


}




**Note that I ended up switching my 'Lookup Multiple Choice' fields to 'Select Box' fields since setting the reference qualifier would unnecessarily burden the server.   The choice lists are now populated via the client script.


View solution in original post

8 REPLIES 8

I forgot to mention, I'm running Dublin currently.


I've read those Wiki pages, but they don't address setting the reference qualifier programmatically.



I want to do something like this:



arrCategories = ['Memory','CPU','Hard Drive'];


sc_item = current.cat_item.sys_id;


myField = g_form.getReference('Attribute1');


myField.ref_qual_elements = "javascript:'model_1.sys_id='+ sc_item +'^model_2.model_category.name=' + arrCategories[0]";


marcguy
ServiceNow Employee
ServiceNow Employee

Can you not call the ref qualifier script include in the normal way i.e.



javascript:myRefQual() in the attributes of the variable and then evaluate the current item etc in that script?



http://wiki.servicenow.com/index.php?title=Reference_Qualifiers#JavaScript_Calls


mguy,


It's a good suggestion, I'm not sure if this will work as well though since each variable in this case would have a unique validation based on the item and the compatible list of items attached to this item.