How do i configure a date/time field that fetch the date where the risk event is in analyze stage

ChuanYanF
Tera Guru

Dear experts,

 

I try to create a date/time field called analyze start date and create a new business rule to fetch the date where the state changes to Analyze and before update. The execution script is as below, but it does not work as it won't show any date data. What do i need to do to make it work?

(function executeRule(current, previous) {
    if (!current.u_analyze_start_date && current.state == 2) {
        current.u_analyze_start_date = new GlideDateTime();
    }
})(current, previous);
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@ChuanYanF 

Seems your business rule condition is not working

I will suggest to use business rule filter condition for this and simply use this script

current.u_analyze_start_date = new GlideDateTime();

OR

try this

(function executeRule(current, previous) {

if (current.u_analyze_start_date == '' && current.state.toString() == '2') {
current.u_analyze_start_date = new GlideDateTime();
}

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Thanks for the response but the script u suggested still does not work.