How to get sla definition name based on categories which are related to catalog item

vamshi2
Tera Contributor

Hi Team,

 

How to get sla definition name based on categories which are related to catalog item

 

Thanks & Regards,

Ramu.

1 REPLY 1

PrashantLearnIT
Giga Sage

Hi @vamshi2 

 

You can utilise below scripts - 

 

// Get SLA definition names based on catalog item categories
var catItem = new GlideRecord('sc_cat_item'); // Catalog Item table
catItem.get('sys_id', '<catalog_item_sys_id>'); // Replace with actual catalog item sys_id

if (catItem.isValidRecord()) {
// Get categories of the catalog item
var categories = [];
var catMapping = new GlideRecord('sc_item_category_mtom'); // Catalog Item to Category Mapping
catMapping.addQuery('sc_cat_item', catItem.sys_id);
catMapping.query();
while (catMapping.next()) {
categories.push(catMapping.sc_category.sys_id);
}

// Fetch SLA definitions related to these categories
var slaDefinitions = [];
var sla = new GlideRecord('contract_sla'); // SLA Definition table
sla.addQuery('task_type', 'sc_req_item'); // Assuming SLAs are defined for request items
sla.addQuery('category', 'IN', categories); // Replace with the field mapping SLA categories if needed
sla.query();
while (sla.next()) {
slaDefinitions.push(sla.name.toString());
}

// Output SLA names
gs.print('SLA Definitions: ' + slaDefinitions.join(', '));
}

 

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************