Hide Empty Variables in RITM and Task

Santhosh23
Tera Expert

Hi All,

I am working in service catalog. after submitting the service catalog i want to display only the variables which is available on the form view. I wrote some UI policy to hide some fields based on conditions.

But in RITM and Task all variables is showing including empty variablles. could you please help me on this.

 

 

11 REPLIES 11

Jaspal Singh
Mega Patron
Mega Patron

Hi Santhosh,

 

The same UI Policies that runs on the Form level before submission of Catalog Item needs to have 

Applies on Catalog Tasks-

Applies on Requested Items-

Applies on Catalog item view-

 

marked as True.

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

Hi Jaspal, Thanks for the response, yes it is applied. I am having 100 plus variables in service catalog. Which will show based on variables selected. For one of the variables user is entering only 4 variables. But after submitting the catalog item in ritm it is showing all 100 variables in ritm and SC task under variables. Requirement is I want to show only the variables which user is entering the input. Please help me on this.

Hi Santhosh,

So here is an approach

1) create display business rule on sc_req_item and sc_task table; ensure this BR runs only for your catalog item

2) get all variables belonging to this RITM

3) determine which variables are empty

4) store them in an array and store this in g_scratchpad variable

5) create catalog client script which applies on RITM and TASK view and iterate over the array from scratchpad and hide them using setDisplay

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

I am using this script and still the uncheck checkbox is still visible. could you pleaase help on this.

 

(function executeRule(current, previous /*null when async*/) {

//Check to see if a variable pool exists
var count = 0;
for(vars in current.variable_pool){
count++;
break;
}

//If a variable pool exists then collect empty variable names
if(count > 0){
var emptyVars = [];
var table = current.getTableName();
//Query for the 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'){
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);
}
itemVars.addNullQuery('sc_item_option.value');
itemVars.addQuery('sc_item_option.value', false);
//itemVars.addQuery('sc_item_option.value','!=',true);
//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.query();
while(itemVars.next()){
//Add variable names to the emptyVars array
emptyVars.push(itemVars.sc_item_option.item_option_new.name.toString());
}
}
else{
//All other variables pulled from 'question_answer' table
var producerVars = new GlideRecord('question_answer');
producerVars.addQuery('table_sys_id', current.sys_id);
producerVars.addNullQuery('value');
producerVars.addQuery('value', false);
//producerVars.addQuery('value','!=',true);
//Exclude Label and Container variables
producerVars.addQuery('question.type', '!=', 11);
producerVars.addQuery('question.type', '!=', 19);
producerVars.addQuery('question.type', '!=', 20);
producerVars.query();
while(producerVars.next()){
//Add variable names to the emptyVars array
emptyVars.push(producerVars.question.name.toString());
}
}

//Store the result in the scratchpad
g_scratchpad.emptyVars = emptyVars.join();
}
})(current, previous);