- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 11:18 AM
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!!
Solved! Go to Solution.
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 11:35 AM
hello
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 11:35 AM
hello
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 11:35 AM
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.***

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 06:44 AM
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);