Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

I need to calculate the time between sys_created_on and the first status change

Jerome MAISETTI
Mega Guru

Hello All
I need your precious help again 🙂
I've created a field on the task table called "Reaction Time".
I need this field to be a calculation between the ticket creation and the first status change.
I already created a field that does the calculation between sys_created_on and requested date but I have to admit that I don't know how to achieve this new one.

Here is my first script

runCalculateTime();

function runCalculateTime() {

    var laterDate = new GlideDateTime(''+current.sys_created_on);
    var earlierDate = new GlideDateTime(''+current.requested_by_date);

    var duration = new GlideDuration();
    duration = GlideDateTime.subtract(earlierDate, laterDate);

    current.u_ticket_creation_delay = duration;

How can I catch up the first status change ?

Thanks

Jérôme.

1 ACCEPTED SOLUTION

SumanthDosapati
Mega Sage
Mega Sage

Hi @Jerome MAISETTI ,

You can try an AFTER  UPDATE business rule as below

Condition : 'Status' Changes

                    AND

                  'ReactionTime' IS NOT EMPTY

Script:

var created = new GlideDateTime(''+current.sys_created_on);
    var updated = new GlideDateTime(''+current.sys_updated_on);

    var duration = new GlideDuration();
    duration = GlideDateTime.subtract(created, updated);

    current.u_reaction_time = duration; //update your reaction time field name
	current.setWorkflow(false);
	current.update();

 

Mark as correct and helpful if it solved your query.

Regards,
Sumanth

 

View solution in original post

5 REPLIES 5

SumanthDosapati
Mega Sage
Mega Sage

Hi @Jerome MAISETTI ,

You can try an AFTER  UPDATE business rule as below

Condition : 'Status' Changes

                    AND

                  'ReactionTime' IS NOT EMPTY

Script:

var created = new GlideDateTime(''+current.sys_created_on);
    var updated = new GlideDateTime(''+current.sys_updated_on);

    var duration = new GlideDuration();
    duration = GlideDateTime.subtract(created, updated);

    current.u_reaction_time = duration; //update your reaction time field name
	current.setWorkflow(false);
	current.update();

 

Mark as correct and helpful if it solved your query.

Regards,
Sumanth