Deepak Ingale1
Mega Sage
Options
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
‎12-21-2018
10:43 PM
Hello,
https://hi.service-now.com/kb_view.do?sysparm_article=KB0714632.
https://community.servicenow.com/community?id=community_question&sys_id=8fc10749db2aef806c1c02d5ca9619fb
There is an issue reported to get label of variable using getGlideObject API, so I have created below utility which gives catalog item variable information in Quenstion and Value format
var UCatalogVariableInfo = Class.create();
UCatalogVariableInfo.prototype = {
initialize: function() {
this.excludedType = ['12','19','20','24','11','14','15','17','23','25'];
this.aru = new ArrayUtil();
},
getVariableInformation : function (grRec) {
var variableNameLabel = {};
var variableInfo = {};
variableNameLabel = this.getVariableNameLablePair(grRec);
for ( var v in variableNameLabel) {
variableInfo[variableNameLabel[v]] = grRec.variables[v].getDisplayValue();
}
return variableInfo;
},
getVariableNameLablePair : function (grRec) {
var variableHash = this.getVariables(grRec);
return variableHash;
},
getVariables : function (grRec) {
var lookupHash = {};
var variableSetSWithItem = this.getVariableSetsForItem(grRec);
var gr = new GlideRecord("item_option_new");
gr.addQuery("cat_item", grRec.getValue("cat_item")).
addOrCondition("variable_set", "IN", variableSetSWithItem);
gr.query();
while (gr.next()) {
if ( this.aru.indexOf(this.excludedType, gr.getValue("type")) == -1 ) {
lookupHash[gr.getValue("name")] = gr.getValue("question_text");
}
}
return lookupHash;
},
getVariableSetsForItem : function (grRec) {
var set = [];
var setItem = new GlideRecord("io_set_item");
setItem.addQuery("sc_cat_item", grRec.getValue("cat_item"));
setItem.query();
while (setItem.next()) {
set.push(setItem.getValue("variable_set"));
}
return set;
},
type: 'UCatalogVariableInfo'
};
Labels:
- 776 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.