- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
A common question I’ve seen is that people have many variables that are empty in the variable editor on your request item or task because they were either optional or hidden on the front-end while submitting the catalog form.
If the variables are empty and you aren’t allowing users to interact with them on the standard forms then there is no point in showing up those variables in the variable editor..
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 <yourCatalogItem>
For SCTASK -> Request Item.Item is <yourCatalogItem>
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
- 14,801 Views
- « Previous
-
- 1
- 2
- 3
- Next »
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.