- 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-26-2014 05:21 AM
Initialize a GlideAjax and call the script include from your client script. Now do a GlideRecord in your script include on 'item_option_new' table to access the reference_qual and update the reference qualifier accordingly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2014 06:18 PM
Srikanth,
that was helpful thanks. I was looking at the wrong table.
'item_option_new' got me much closer. However, there are multiple records in 'item_option_new' for each variable, and I'm not sure how to get the sys_id for the 'item_option_new' record to pass to the script_include..
console.log(g_form.getValue('scAttrib1').toString()); //this returns the sys_id of the current value of the variable
console.log(g_form.getReference('scAttrib1').sys_id); //this returns 'undefined'
The information I'm looking for is available in div id "variable_map".. but I'm not sure how to get to that with Glide.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2014 07:11 PM
This works! I'm not sure if it's the most efficient method though.
map = gel('variable_map');
var items = map.getElementsByTagName("item");
for (var i = 0; i < items.length; i++) {
var item = items.item(i);
var name = item.getAttribute('qname');
var id = item.id;
}
- 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.