Hide empty variables on RITM and TASK record
Below approach can be used to hide those empty variables in the variable editor on RITM and TASK view.
1) Create two Display business rules one each on 'sc_req_item' and 'sc_task' table
-> It would run before the display of any record in the table either sc_req_item or sc_task
2) Determine which variables are empty and store them in scratchpad variable
-> Script would query the ‘sc_item_option_mtom’ table which holds the catalog variable values and collect the variable names for variables which are having empty value; then push them in an array and store the value in scratchpad variable
3) Create an onLoad catalog client script which applies on RITM and TASK view and using the scratchpad variable hide those variables
-> Access the scratchpad variable and iterate over those to hide them
Business Rule: One for Table (sc_req_item) and other for Table (sc_task)
Note: If you want these BR to trigger only for your catalog item then you need to update the BR Condition as below for respective table
For RITM -> Item is
For SCTASK -> Request Item.Item is
BR Script:
var emptyVariables = [];
var tableName = current.getTableName();
var ritmSysId = '';
if(tableName == 'sc_req_item')
ritmSysId = current.getUniqueValue();
if(tableName == 'sc_task')
ritmSysId = current.request_item;
var itemObj = new GlideRecord('sc_item_option_mtom');
itemObj.addQuery('request_item', ritmSysId);
itemObj.addNullQuery('sc_item_option.value');
itemObj.addQuery('sc_item_option.item_option_new.type', '!=', 11); // exclude label
itemObj.addQuery('sc_item_option.item_option_new.type', '!=', 19); // exclude container start
itemObj.addQuery('sc_item_option.item_option_new.type', '!=', 20); // exclude container end
itemObj.query();
while(itemObj.next()){
var name = itemObj.sc_item_option.item_option_new.name;
emptyVariables.push(name.toString());
}
g_scratchpad.emptyVariables = emptyVariables.toString();
Catalog Client Script: onLoad & True for "Applies on Requested Items" , "Applies on Catalog Tasks"
function onLoad() {
if(g_scratchpad.emptyVariables != ''){
var emptyVars = g_scratchpad.emptyVariables.split(',');
for(i = 0; i < emptyVars.length; i++){
g_form.setDisplay(emptyVars[i], false);
}
}
}
BR Screenshot: RITM Table
BR: Task Table
BR Script:
Catalog Client Script Screenshot:
Thanks for reading the blog and do provide your inputs/suggestions if any.
Hope you find this article helpful. Don’t forget to Mark it Helpful, Bookmark.Thanks,
Ankur Bawiskar
Labels:
https://www.servicenow.com/community/developer-blog/hide-empty-variables-on-ritm-and-task-record/ba-p/2292334