Not able to stop after update br for new record

MaharshiC
Tera Contributor

Hi,

I have written this after update br on change of a field and is working fine for existing records but I dont want it to run the very first time the record is creted. The record gets created through an ui action and so the field automatically gets field from the ui action but I want to stop this after update br to work for new records created but rather it should work only when a user manually changes the field.

 

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

    if (!current.isNewRecord()) {

       
            var item = new GlideRecord('x_iem_tqa_work_request_items');
            item.addQuery('associated_work_order_number.sys_id', current.sys_id);
            item.addQuery('tag_report_anomaly_other', 'NOT IN', current.associated_work_request_item_number);
            item.query();
            while (item.next()) {
                item.associated_work_order_number = '';
                item.selected_work_items = false;
                item.state = 'Planning Completed';
                item.update();
            }

      
    }

})(current, previous);

 Is there an alternative to do this? 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@MaharshiC 

if you want this BR to run only for manual changes then in BR condition add this check for empty

current.associated_work_request_item_number.changes() && 
        !current.associated_work_request_item_number.nil()

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@MaharshiC 

if you want this BR to run only for manual changes then in BR condition add this check for empty

current.associated_work_request_item_number.changes() && 
        !current.associated_work_request_item_number.nil()

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

@MaharshiC 

Hope you are doing good.

Did my reply answer your question?

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