Condition Builder Based On Another Field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2016 12:53 AM
Hi All,
I have requirement to show the list of variables and its values in Condition (type: Condition) field based on another field "item"(Reference, Referencing sc_cat_item table).
As of now the condition field is dependent on the field "Table"(Type: Table Name) to show the records.
But i need to select the Question and Value in the condition type field based on the value from "Item" Field.
Please share your ideas if anyone knows to achieve this
Thanks in advance,
AJ.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2016 07:45 AM
If I understand your need correctly, you'll want to do a script include to grab this. I have a similar situation I believe. I have a table that has three fields: Request item (references a catalog item), variable (shows only the variables for the selected catalog item), variable options (shows only the options for the variable selected). This is how the variable and variable option are set up:
And then this is the script include:
variable:function() {
var vbls = ' ';
var req = current.u_request_item;
//return everything if the u_request_item value is empty
if(!req)
return;
//find item_option_new related to the catalog item
var vars = new GlideRecord('item_option_new');
vars.addQuery('cat_item',req);
vars.addQuery('type','!=',20);
vars.addQuery('type','!=',24);
vars.addQuery('type','!=',19);
vars.query();
while(vars.next()) {
if (vbls.length > 0) {
//build a comma separated string of groups if there is more than one
vbls += (',' + vars.sys_id);
}
else {
vbls = vars.sys_id;
}
}
var varset = new GlideRecord('io_set_item');
varset.addQuery('sc_cat_item',req);
varset.query();
while(varset.next()){
var setvar = new GlideRecord('item_option_new');
setvar.addQuery('variable_set',varset.variable_set);
setvar.addQuery('type','!=',20);
setvar.addQuery('type','!=',24);
setvar.addQuery('type','!=',19);
setvar.query();
while(setvar.next()){
if (vbls.length > 0) {
//build a comma separated string of variables if there is more than one
vbls += (',' + setvar.sys_id);
}
else {
vbls = setvar.sys_id;
}
}
}
// return variables
return 'sys_idIN' + vbls;
},
varoption:function() {
var ops = ' ';
var vbl = current.u_variable;
gs.info('varoption running off of variable ' + vbl);
//return everything if the variable value is empty
if(!vbl){
gs.info('running blank vbl loop');
return;
}
var op = new GlideRecord('question_choice');
op.addQuery('question',vbl);
op.query();
while(op.next()) {
gs.info('the current item option is ' + op.value);
if (ops.length > 0) {
//build a comma separated string of options if there is more than one
ops += (',' + op.sys_id);
}
else {
ops = op.sys_id;
}
}
return 'sys_idIN' + ops;
},