The CreatorCon Call for Content is officially open! Get started here.

Calculating a duration from 2 date / time fields in a scoped application

travis_warner
Giga Contributor

I am trying to use a business rule to auto calculate a duration field in that is used in a scoped application.   I need the duration based on the difference of 2 date / time fields   I tried to modify one that we are already using for Problem management but the gs.dateDiff is only available in global.   Below is a copy of the current script being used as well as the error im currently getting.

Screen Shot 2016-11-22 at 9.55.44 AM.png

function onBefore(current, previous) {

    //This function will be automatically called when this rule is processed.

gdt1 = current.u_incident_start.getGlideObject();

gdt2 = current.u_resolution_time.getGlideObject();

current.u_mttr = GlideDateTime.subtract(gdt1.getDisplayValue(),gdt2.getDisplayValue());

current.update();

}

1 ACCEPTED SOLUTION

Thanks Chuck, that got me close.   I had to adjust to the following to make it work but I may have missed something in your original post.


Screen Shot 2016-11-22 at 10.21.13 AM.png


function onBefore(current, previous) {


    //This function will be automatically called when this rule is processed.


current.u_mttr = GlideDateTime.subtract(new GlideDateTime(current.getValue("u_incident_start")), new GlideDateTime(current.getValue("u_resolution_time")));


current.update();


}


View solution in original post

7 REPLIES 7

Chuck Tomasi
Tera Patron

Forgot my reference to GlideDateTime.subtract()


jonascosta
Tera Contributor

In Scoped applications



Client Script


Captura de Tela 2018-02-12 às 13.45.16.png



Script Include


Captura de Tela 2018-02-12 às 13.43.27.png



Result


Captura de Tela 2018-02-12 às 13.46.30.png


Thank you. this worked for me.