Change Risk Assessment Metric Query

Joshuu
Kilo Sage

Hi All,

 

By using Risk Assessment Metric Script option can we achieve the below requirement?

 

Count the number of impacted CI's on the change related list called "Impacted CI's" and return the relevant value.
If the count is between 1 to 5 then select 1 to 5 option on the metric.
If the count is between 1 to 6 then select 6 to 10 option on the metric.

 

Thanks & Regards.

 

 

7 REPLIES 7

Rajdeep Ganguly
Mega Guru


Yes, you can achieve this requirement by using a Risk Assessment Metric Script. Here's a sample script and steps to implement it:

1. Navigate to Risk > Risk Assessment > Metrics.
2. Click on New to create a new metric.
3. Fill in the necessary details like Name, Description, etc.
4. In the Type field, select "Script".
5. In the Script field, paste the following script:

javascript
(function execute() {
var changeSysId = current.sys_id;
var ciCount = new GlideAggregate('task_ci');
ciCount.addQuery('task', changeSysId);
ciCount.addAggregate('COUNT');
ciCount.query();
if (ciCount.next()) {
var count = ciCount.getAggregate('COUNT');
if (count >= 1 && count <= 5) {
return '1 to 5';
} else if (count >= 6 && count <= 10) {
return '6 to 10';
}
}
return 'None';
})();


6. Save the metric.
7. Now, this metric will count the number of impacted CI's on the change related list called "Impacted CI's" and return the relevant value based on the count.

Please note that you need to replace 'task_ci' with the actual table name of your "Impacted CI's" related list and 'task' with the field that references the change record. Also, replace '1 to 5' and '6 to 10' with the actual options you have on your metric.

This script will count the number of impacted CI's related to the change record and return the relevant value based on the count. If the count is between 1 to 5, it will return '1 to 5'. If the count is between 6 to 10, it will return '6 to 10'. If there are no impacted CI's, it will return 'None'.


nowKB.com

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER

Hi @Rajdeep Ganguly ,

 

Thank you for your response.

So, as per the below screenshot, will it use the below mentioned value based on this script ?

For ex, if it returns 1 to5 will it take value as '20' to calculate further?

priyarao_0-1706089628438.png

 

or do I need to add something as below.

 

if (count >= 1 && count <= 5) {
return '20';
} else if (count >= 6 && count <= 10) {
return '40';
}
}

 

- If the count is between 1 and 5 (inclusive), the script will return '20'.
- If the count is between 6 and 10 (inclusive), the script will return '40'.
- If the count is outside these ranges, the function will not return a value.

If you want to handle counts outside these ranges, you should add more conditions or a default return value. For example:

javascript
if (count >= 1 && count <= 5) {
return '20';
} else if (count >= 6 && count <= 10) {
return '40';
} else {
return '0'; // default value
}


This script will return '0' if the count is less than 1 or greater than 10.


nowKB.com

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Joshuu 

 

May i know what you want to archive with this? means business use case? Are you going to use the count for risk calculation?

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************