Calculation value

akin9
Tera Contributor

Hello Experts,

 

We want to calculate the request or change created between approval approved days calculation.

 this is totally new requirement for us.

created new field on the approval table.

field name - "Open days"

field type - Date/time.

Requirement .

How to achieve the calculation created b/w approved kindly support.

 

 

Thanks!

1 ACCEPTED SOLUTION

Gummagatta Hars
Mega Guru

Hi @akin9 ,

 

You need to create the custom field with the type as "Duration" in order to store the duration between approval created, action taken and update this field from a after business rule. I have implemented the solution in my PDI, attached the below screenshots for your reference.

 

Let me know in case if you have any further queries.

 

If the solution shared works for you, please "Accept as Solution" and mark " Helpful." 

 

Thanks,

Gummagatta Harshavardhana

 

Dictionary Entry -

GummagattaHars_0-1706641219545.png

 

Business rule condition -

GummagattaHars_1-1706641268444.png

 

Business rule script -

.

    var gdt1 = GlideDateTime(current.getValue('sys_created_on')); // get the request opened date and time
    var gdt2 = GlideDateTime(current.getValue('sys_updated_on')); // get the request closed date and time
    var duration = gs.dateDiff(gdt1.getDisplayValue(), gdt2.getDisplayValue(), false); // Calculate the difference bewtween opened and approved time

    var grAppr = new GlideRecord('sysapproval_approver');
    grAppr.addQuery('sys_id', current.getUniqueValue());
    grAppr.query();
    if (grAppr.next()) {
        grAppr.u_approval_duration = duration; // update the duration field with the difference
		grAppr.update();
    }

Output -

GummagattaHars_2-1706641427623.png

 

 

 

View solution in original post

6 REPLIES 6

Hi Akin,
 
Yes, we can exclude weekends and off business hours. The below script will only calculate the business hours excluding weekends.
 

If the solution shared works for you, please "Accept as Solution" and mark " Helpful." 

 

Thanks,

 

Gummagatta Harshavardhana

 

 

 var gdt1 = GlideDateTime(current.getValue('sys_created_on')); // get the request opened date and time
    var gdt2 = GlideDateTime(current.getValue('sys_updated_on')); // get the request closed date and time
    // var duration = gs.dateDiff(gdt1.getDisplayValue(), gdt2.getDisplayValue(), false); // Calculate the difference bewtween opened and closed time
    var schedule = new GlideSchedule();
    schedule.load('090eecae0a0a0b260077e1dfa71da828'); // loads "8-5 weekdays excluding holidays" schedule
    var duration = schedule.duration(gdt1, gdt2);

    var grAppr = new GlideRecord('sysapproval_approver');
    grAppr.addQuery('sys_id', current.getUniqueValue());
    grAppr.query();
    if (grAppr.next()) {
        grAppr.u_approval_duration = duration; // update the duration field with the difference
        grAppr.update();
    }

 

Hi @Gummagatta Hars 

Thank you very much for your Quick support, its working fine for me.