How to Calculate the lead time of change request?

Khaja Shaik
Tera Contributor

Hi All, 

Need help!! 

I have a requirement to calculate the lead time for the change request, I have 3 levels of approvals(technical group, CAB and PCB approvals) 

Lead time : The difference between 3rd level approval requested time and the planned start date time of the change. 

How to calculate the lead time? 

Thanks in advance!! 

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

hello @Khaja Shaik ,

try this script 

IF YOU ARE TRYING IT IN BUSINESS RULE ON CHANGE REQUEST FORM TRY BELOW

var dur;
var app = new GlideRecord('sysapproval_approver');
app.addQuery('sysapproval',current.sys_id);
app.addQuery('<field_name>',<value>); // replace the query to find out PCB approval
app.query();
if(app.next())
{
 dur = new GlideDuration();
dur.setValue(app.sys_created_on); 
}

var duration2 = new GlideDuration();
duration2.setValue(current.planned_start_date); //REPLACE PLANNED START DATE FIELD NAME ACCORDING TO THE INSTANCE

var answer = duration2.subtract(dur);
gs.info('Lead time'+answer.getDisplayValue());

Hope this helps 

MARK MY ANSWER CORRECT IF THIS HELPS YOU

View solution in original post

3 REPLIES 3

Mohith Devatte
Tera Sage
Tera Sage

hello @Khaja Shaik ,

try this script 

IF YOU ARE TRYING IT IN BUSINESS RULE ON CHANGE REQUEST FORM TRY BELOW

var dur;
var app = new GlideRecord('sysapproval_approver');
app.addQuery('sysapproval',current.sys_id);
app.addQuery('<field_name>',<value>); // replace the query to find out PCB approval
app.query();
if(app.next())
{
 dur = new GlideDuration();
dur.setValue(app.sys_created_on); 
}

var duration2 = new GlideDuration();
duration2.setValue(current.planned_start_date); //REPLACE PLANNED START DATE FIELD NAME ACCORDING TO THE INSTANCE

var answer = duration2.subtract(dur);
gs.info('Lead time'+answer.getDisplayValue());

Hope this helps 

MARK MY ANSWER CORRECT IF THIS HELPS YOU

Yousaf
Giga Sage

Hi Khaja,

Please refer to these.

Change Management - Lead Times

Auto-populating and validating date fields

 

Mark Correct or Helpful if it helps.


***Mark Correct or Helpful if it helps.***

Sudeepta
Tera Contributor

I want to refer a different scenario. Suppose you want to trigger a notification where you want to capture -How much time got elapsed.

Lead time : The difference between 3rd level approval requested time and the planned start date time of the change.

The field name of Lead time is Adherence to the established IT Change lead times with a value Yes/No

so when it changes to 'No', email should be triggered. In that case, you need to write a email script where you'll capture a time difference between sys_created_on and the time when 3rd level approval is requested.

Name: lead_time_left

Script

 

(function runMailScript(current, template, email, email_action, event) {

var gr = new GlideDateTime();
var gr1 = new GlideDateTime();
var getrec = new GlideRecord('change_request');
getrec.query();
if (getrec.next()) {
gr = current.sys_created_on;
gr1 = current.u_lead_time; //custom field 
var df = gs.dateDiff(gr.getDisplayValue(), gr1.getDisplayValue(), false);
template.print(df);
}

})(current, template, email, email_action, event);

 

 

Now calling the same email script in the email notification: Time Elapsed: ${mail_script:lead_time_left} ( Format - Hr:Min:Sec)
 
Output: attached ss
lead time diff.png