calculate business duration based on start date & end data via after business rule

Mabubi
Tera Contributor
calculate business duration based on start & end date fields.Start date value will set once state changes to work in progress & end date will set once state move to close complete. This scenario which Business rule will use.
i have used after business rule. But  can't use current.update() right.so i have writtern aync also its not setting the business duration.
not getting this log as well -gs.info("business_duration"+current.business_duration);
 
Script:
(function executeRule(current, previous /*null when async*/) {

 

    // Add your code here
    gs.info("check br duration");
    var start = new GlideDateTime(current.work_start.getDisplayValue());
var end = new GlideDateTime(current.work_end.getDisplayValue());
var duration = GlideDateTime.subtract(start, end);
current.business_duration = duration;
//current.update();
gs.info("business_duration"+current.business_duration);

 

})(current, previous);
 
 
could you please confirm me any idea.how to proceed any other option.
7 REPLIES 7

Bert_c1
Kilo Patron

If you change your BR to run 'Before', no current.update(); will be needed. Please specify the table your BR is defined on. Seems your script logic is correct.

Mabubi
Tera Contributor

tried before br also log is not getting for this -gs.info("business_duration"+current.business_duration);

Do you have conditions on the BR for work_start and work_end not being empty? I tested the script logic on the incident table and it works.

Mabubi
Tera Contributor

yes i have the condition the start date is not empty & end date is not empty.can you share your script .how its working for you