Tanushree Maiti
Tera Patron

Hi @oluseyiasol 

 

Try with this:

Update the Business Rule Configuration

  • When: Before
  • Insert/Update: Checked
  • Filter Conditions: [State] [is one of] [Closed Complete, Closed Incomplete]

 

(function executeRule(current, previous /*null when async*/) {

        if (!current.opened_at.nil() && !current.closed_at.nil())

      {

        var start = new GlideDateTime(current.opened_at.getDisplayValue());

        var end = new GlideDateTime(current.closed_at.getDisplayValue());

        var duration = GlideDateTime.subtract(start, end);

         current.business_duration = duration;

    }

})(current, previous);

 

Also check solution given in the post: https://www.servicenow.com/community/developer-forum/how-to-set-business-duration-field-on-ritm/m-p/...

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti