can you provide script to auto populating category and subcategory based on the CI ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2024 12:16 AM
provide script to auto populating category and subcategory #incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2024 12:36 AM
you can use onChange client script on CI field and set the values.
but ensure you need to set correct subcategory since subcategory has dependency on category
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2024 12:51 AM
Hi @RMU ,
Create a onchange client scritp as below:
var conItem = g_form.getValue('cmdb_ci');
if (conItem != '' )
{
if(conItem == 'xxxxxxxxxxxxxxxxxxxxxxxxxx'){
g_form.setValue('category', 'value');
g_form.setValue('sub_category', 'value');
}else if (conItem == 'xxxxxxxxxxxxxxxxxxxxxxxxxx'){
g_form.setValue('category', 'value');
g_form.setValue('sub_category', 'value');
}else if (conItem == 'xxxxxxxxxxxxxxxxxxxxxxxxxx'){
g_form.setValue('category', 'value');
g_form.setValue('sub_category', 'value');
}
}
and so on.........
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 03:10 AM
Hi @RMU ,
You'll have to write a script to fetch the category and subcategory from the related Configuration Item (CI) and populate the corresponding fields on the Incident form.
Try below code in BR:
(function executeRule(current) {
// Check if Configuration Item (CI) is populated
if (current.cmdb_ci.nil())
return;
// Query Configuration Item to get its category and subcategory
var ciGR = new GlideRecord('cmdb_ci');
if (ciGR.get(current.cmdb_ci)) {
// Populate Category and Subcategory fields on the Incident form
current.category = ciGR.getValue('category');
current.subcategory = ciGR.getValue('subcategory');
}
})(current);
If you find my response helpful, please consider selecting "Accept as Solution" and "Helpful" .
Thanks,
Anusha