ADD Query Condition in Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 01:47 AM - edited 01-29-2024 01:50 AM
Hi All,
Below is the Change Risk Assessment script. It is not working as expected. It is always going to the else part. Requirement is, If there were any failed changes logged for the Primary CI in the past 6months then default the metric should be '300' otherwise '150'.
Please check if my conditions are correct or not.
var ci = new GlideRecord('change_request');
ci.addQuery('cmdb_ci', primary);
ci.addQuery('close_code', 'unsuccessful');
ci.addEncodedQuery('sys_updated_onONLast6months@javascript:gs.beginningOfLast6Months()@javascript:gs.endOfLast6Months()');
ci.query();
actual_result = ci.getRowCount();
if (actual_result>=1) {
scaled_result = 300;
} else
scaled_result = 150;
Thanks & Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 02:11 AM
Hi @Joshuu
I can see you have made a query with cmdb_ci as Primary. Can you please confirm if primary is a variable ? Also, use gs.info(actual_result); before if condition to check the number of rows being returned from your query to debug it further.
You can even apply manual filters as well on the change_request table to see if you are able to get the relevant records or not to set the metric.
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 02:54 AM
Hi @Amit Verma ,
// The following variables are available:
// - primary: contains the sys_id of the assessable object to be evaluated
// - string_result: the script sets the display string value for this metric to this variable
// - actual_result: the script sets the actual value for this metric to this variable
// - scaled_result: the script sets the scaled value (used in calculations) for this metric to this variable
//
// For example:
// var gr = new GlideRecord('cmdb_ci');
// gr.addQuery('manufacturer', primary);
// gr.query();
// actual_result = gr.getRowCount();
// string_result = actual_result + '';
// if (actual_result > 100) scaled_result = 5;
// else scaled_result = 1;
var ci = new GlideRecord('change_request');
ci.addQuery('cmdb_ci', primary);
ci.addEncodedQuery('close_code=unsuccessful^sys_updated_onONLast6months@javascript:gs.beginningOfLast6Months()@javascript:gs.endOfLast6Months()'); // Filter for changes in the past 6 months
ci.query();
actual_result = ci.getRowCount();
string_result = actual_result + '';
gs.info('review Found! actual_result=' + actual_result);
if (actual_result >= 1) {
scaled_result = 300;
} else {
scaled_result = 150;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 03:00 AM
hi @Joshuu ,
What is primary in your query variable or some hardcoded value , if it is a variable then you might need to try variablename.getDisplayValue and see if it works
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 02:12 AM
Also, where you have defined the scaled_result variable ?
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.