How to Hide Empty Variables of RITM and Task

Community Alums
Not applicable

Hi All,

 

Service catalog variables can be a challenge to deal with on standard forms when they are displayed in a variable editor,

one of these challenges…making the variables read only, so that they can’t be modified after the initial submission through the service catalog interface. a lot of variables that end up empty in the variable editor on your request item or task because they were optional or hidden on the front-end catalog form.  If the variables are empty don't show up at all in the variable editor. 

 

Rafmine_0-1696824709267.png

 

Any help is highly appreciated.

 

Regards,

Uzmine

3 REPLIES 3

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Community Alums ,

 

U might have created initial ui policy for hiding n displaying variables on catalog form correct. Just mark the "Applies on Requested Item checkbox & Applies on Catalog Task checkbox" to make it disappear on RITM & TASK level as well. By default only Applies on Catalog item checkbox is checked.

 

The above should work.

 

Mark my answer helpful & accepted if it helps you resolve your issue.

 

Thanks,

Danish

Aman Kumar S
Kilo Patron

Hi @Community Alums 

You can follow article to fix your issue, it has detailed steps:

https://www.servicenow.com/community/developer-blog/hide-empty-variables-on-ritm-and-task-record/ba-p/2292334

 

 

Best Regards
Aman Kumar

shyamkumar VK
Kilo Patron

Hi @Community Alums ,

 

Follow the below process

 


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);
      }
   }
}

Ref :https://www.servicenow.com/community/developer-blog/hide-empty-variables-on-ritm-and-task-record/ba-p/2292334

 

Please mark helpful and accept the solution if this helped for you

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar