Error using new GlideDateTime.subtract()

e_wilber
Tera Guru

I am trying to use the following code to get the duration between when the record was created and NOW (to get open-to-resolve duration).

(function executeRule(current, previous /*null when async*/) {
    current.u_time_to_resolve = new GlideDateTime.subtract(current.sys_created_on, new GlideDateTime().getDisplayValue());
})(current, previous);

I am getting this error when running this business rule though. Any idea what is happening? This is a scoped app.

Error running business rule 'Record Time to Resolve' on sn_customerservice_customer_care: CS0001798, exception: org.mozilla.javascript.EvaluatorException: Can't find method com.glide.glideobject.GlideDateTime.subtract(com.glide.script.glide_elements.GlideElementGlideObject,string). (sys_script.82d753881b7c91506fc6a8a8b04bcb9a.script; line 3)

6 REPLIES 6

I am beginning to wonder if this just won't work in a scoped app.

I have updated to

    var startDate = current.sys_created_on.getDisplayValue();
    var endDate = new GlideDateTime(new GlideDateTime().getDisplayValue());
        
    var dur = GlideDateTime.subtract(startDate, endDate);
    gs.addInfoMessage(dur);

And now I'm getting an error

Error running business rule 'Record Time to Resolve' on sn_customerservice_customer_care: CS0001798, exception: org.mozilla.javascript.EvaluatorException: Can't find method com.glide.glideobject.GlideDateTime.subtract(string,com.glide.script.fencing.ScopedGlideDateTime). (sys_script.82d753881b7c91506fc6a8a8b04bcb9a.script; line 7)

Try using:

var endDate= new GlideDateTime();
var startDate= new GlideDateTime(incidentGR.sys_created_on.getDisplayValue());
var diff = GlideDateTime.subtract(today, endDate);
gs.info(diff.getDisplayValue());
gs.info(diff.getRoundedDayPart());
 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

 

Best Regards
Aman Kumar