How to auto populate configuration item based on category and sub-category in incident form

sugand
Tera Contributor

Hi, 
I need to auto populate configuration item based on the selection of category and sub category on incident form. 

For example:

Category: Network

Subcategory: Switches

Configuration item: Should populate only datas from (cmdb_ci_ip_switch)

 

Can anyone help me in achieving this. 

 

Thanks,

Sugand

3 REPLIES 3

Vishwa Pandya19
Mega Sage

Hello,

 

Please check below article, it may help you.

https://www.servicenow.com/community/itsm-blog/filtering-ci-s-a-reference-qualifier-example/ba-p/226...

 

 

If my answer has helped you in any way please mark it as correct or helpful.

GuruP
Tera Contributor

Hi  sugand,

 

You can achieve this also with Date Lookup Defination.

 

 

Thanks,

Gaurav

Adarsh3003
Giga Guru

Hi @sugand ,

 

Please follow below steps for populating CI ...  

1. Navigate to *System Definition > Business Rules*.
2. Click *New*.
3. Enter the following information:
- *Name*: Populate Configuration Item
- *Table*: Incident
- *When*: After
- *Condition*: Category is not empty
- *subcategory* : subcategory is not empty
- *Script*:

```
// Get the category value
var category = current.category;

// Get the sub category value
var subCategory = current.subcategory;

// Check if the category is not empty
if (category != '') {
// Query the cmdb_ci table for CIs that have the same category
var ciQuery = new GlideRecord('cmdb_ci');
ciQuery.addQuery('category', category);

// If CI is found, then set the configuration item field
if (ciQuery.next()) {
current.configuration_item = ciQuery.sys_id;
}
}
```

4. Click **Save**.

5. Navigate to **Incident** form.
6. Select a value for **Category**.
7. The **Configuration Item** field will be auto populated with the appropriate CI.

 

 

If this is helpful for you, Please mark Helpful and Correct solution


Thanks & Regards
Adarsh Verma