- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2014 04:52 PM
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
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2014 01:33 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2014 10:18 PM
Hi,
Look it. It will help you.
Reference Qualifiers for Service Catalog Variables - ServiceNow Wiki
Reference Qualifiers - ServiceNow Wiki
Thanks,
Sanjeev Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2014 12:31 AM
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]";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2014 01:12 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2014 07:10 PM
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.