- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2024 09:15 AM
I have a Catalog Item (Firewall Rule Change) that generates a Change Request after the RITM is approved. The RITM is set to Closed Complete after the Approval activity completes.
There is a new requirement to capture the Duration of when the Request is opened (Waiting for Approval) to when it gets approved (Complete).
I created a new Metric Definition that runs on the Requested Item (sc_req_item) table. When I set the Type as "Field value duration", it sets the duration correctly. It only calculates the difference between created on and closed, which is fine because that essentially is what I need.
However, I only want the Metric to capture records if the Catalog Item = Firewall Rule Change, so I have to set the Type to “Script calculation” and use the Script. This is where I’m struggling.
The stage transitions through waiting for approval to fulfillment, to complete. I would like to get the Duration of when the RITM is created (Stage = waiting_for_approval) to when it is completed (Stage = complete). My script is not working. Any help appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2024 07:52 AM - edited 03-02-2024 07:53 AM
Hi Cory,
I would do something like this
// definiton: GlideRecord - this row
// current: current record
if (current.sc_cat_item == 'firewall') {
if (current.stage== 'requested')
createMd();
else if(current.stage== 'approved')
closeMd();
}
//calls the script include "MetricInstance" and create a metric instance
function createMd() {
var md = new MetricInstance(definition, current);
// check if a metric instance exists already
if (md.metricExists()) {
return;
}
var gr = md.startDuration();
}
//calls the script include "MetricInstance" and close the metric instance
function closeMd() {
var md = new MetricInstance(definition, current);
if (md.metricExists()) {
md.endDuration();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 10:46 AM - edited 03-07-2024 10:47 AM
Thank you for the information. Works great! I just needed to change the stage values to what the workflow is setting them to, and it works great. Modified script below. Thanks!
// definiton: GlideRecord - this row
// current: current record
if ((current.cat_item.name == "Firewall Rule Change")){
if(current.stage == 'waiting_for_approval')
createMd();
else if(current.stage == 'complete')
closeMd();
}
//calls the script include "MetricInstance" and create a metric instance
function createMd() {
var md = new MetricInstance(definition, current);
// check if a metric instance exists already
if (md.metricExists()) {
return;
}
var gr = md.startDuration();
}
//calls the script include "MetricInstance" and close the metric instance
function closeMd() {
var md = new MetricInstance(definition, current);
if (md.metricExists()) {
md.endDuration();
}
}