Extract variable in RITM and display except those who belong to vs_requestor variable set

avinashdubey103
Tera Guru

Hi , I have a requirement to displaye all the variable present in the RITM but excluding the variables that are from vs_requestor variable set :

 

I have written the followling code and applied the filter condtion :  if (current.variable_pool[vars].variable_set !== 'vs_amdocs_requestor') {

 

Still it is taking all the variables 

 

 

code:

 


    var table = current.getTableName();
var count = 0;
if (table == 'sysapproval_approver') {
    count = 1;
}else {
    for (vars in current.variable_pool) { //Add a condition to check if the variable is not from vs_amdocs_requestor variable set
        if (current.variable_pool[vars].variable_set !== 'vs_amdocs_requestor') {
            count++;

        }
    }
}

if(count > 0){
    var mvalue = '';
    var list = [];
    var display = [];
    template.print('<table border="1">');
   
    //Query for the non-empty variables for this record
    //Catalog item and task variables pull from 'sc_item_option_mtom' table
    if(table == 'sc_req_item' || table == 'sc_task' || table == 'sysapproval_approver') {
        var itemVars = new GlideRecord('sc_item_option_mtom');
       
        if(table == 'sc_req_item'){
            itemVars.addQuery('request_item', current.sys_id);
           
        }
        if(table == 'sc_task'){
            itemVars.addQuery('request_item', current.request_item.sys_id);
           
        }
        if(table == 'sysapproval_approver'){
            itemVars.addQuery('request_item', current.sysapproval.sys_id);
        }
        itemVars.addNotNullQuery('sc_item_option.value');
       
        //Exclude Label and Container variables
        itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 11);
        itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 19);
        itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 20);
        itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 24);
        itemVars.orderBy('sc_item_option.order');
       
        itemVars.query();
        while(itemVars.next()){
            template.print("<tr>");
            template.print("<td>"+itemVars.sc_item_option.item_option_new.question_text+"</td>");
            mvalue = itemVars.sc_item_option.value;
           
            // Check if the value is from the reference field
            if (itemVars.sc_item_option.item_option_new.type == '8') {
                var grRefTable = new GlideRecord(itemVars.sc_item_option.item_option_new.reference);
                grRefTable.addQuery('sys_id',mvalue);
                grRefTable.query();
                if (grRefTable.next()) {
                    mvalue = grRefTable.getDisplayValue();
                }
                template.print("<td>"+mvalue+"</td>");
                template.print("</tr>");
            }
           
            // Check if the type is List Collector
            if(itemVars.sc_item_option.item_option_new.type == '21') {
                list = itemVars.sc_item_option.value.split(',');                
                for(var i=0; i<list.length; i++){
                    var grListTable = new GlideRecord(itemVars.sc_item_option.item_option_new.list_table);
                    grListTable.addQuery('sys_id',list[i]);
                    grListTable.query();
                    if (grListTable.next()) {
                        display.push(grListTable.getDisplayValue());                        
                    }
                }
                template.print("<td>"+display+"</td>");
                template.print("</tr>");
            }
           
            // Check if the type is Select Box
            if(itemVars.sc_item_option.item_option_new.type == '5') {
                var grQuestion = new GlideRecord('question_choice');
                grQuestion.addQuery('question', itemVars.sc_item_option.item_option_new);
                grQuestion.addQuery('value', itemVars.sc_item_option.value.toString());
                grQuestion.query();
                if(grQuestion.next()){
                    mvalue = grQuestion.getValue('text');
                }
                template.print("<td>"+mvalue+"</td>");
                template.print("</tr>");
            }
           
            //For rest of the types
            if(itemVars.sc_item_option.item_option_new.type != '21' && itemVars.sc_item_option.item_option_new.type != '8' && itemVars.sc_item_option.item_option_new.type != '5' )
                {
                template.print("<td>"+mvalue+"</td>");
                template.print("</tr>");
            }
        }
    }
    template.print("</table>");
}


3 REPLIES 3

Kartik Magadum
Kilo Sage

Hello @avinashdubey103 

Please try below code

var table = current.getTableName();
var count = 0;

if (table == 'sysapproval_approver') {
    count = 1;
} else {
    for (vars in current.variable_pool) {
        var variableSet = current.variable_pool[vars].item_option_new.variable_set;

        // Add a condition to check if the variable definition's variable set is not 'vs_amdocs_requestor'
        if (variableSet !== 'vs_amdocs_requestor') {
            count++;
        }
    }
}
// Rest of your code...

 

Thank You

Kartik Magadum

Hi , it is printing the  vs_amdocs_requestor vairables also

Simon Christens
Kilo Sage

Hi,

You can also look into:

GlobalServiceCatalogUtil
There you can see all the variables with values etc and if its in a variable set

 

var varsArr = new global.GlobalServiceCatalogUtil().getVariablesForTask(current, true);
gs.info(global.JSON.stringify(varsArr), null, 2);