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

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

 

 

 

Hi @Gummagatta Hars ,

 

Thanks for the Quick reply !

Its working fine and one more question

Days will calculate 24hrs?

2.Can we use this on reports as well? Thanks!

Hi @akin9 ,

 

Yes a day will be 24 hours and this field can be used in reports.

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

Hi @Gummagatta Hars 

 

Is it possible to restict saturday and sunday ?

and for business hours. thanks!