Script not working

sunil10
Tera Contributor

Hi all

I am using below business rule on user table after update and active changes to false, everything is working fine state getting update worknotes getting updated but autosysfields not working, please suggest

 

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


    var grScReqItem = new GlideRecord('sc_req_item');
    grScReqItem.addEncodedQuery("cat_item=32524947c32b9a1062c17ebdc00131a5^stateNOT IN3,4,7^requested_for=" + current.sys_id);
    grScReqItem.query();
    while (grScReqItem.next()) {
 
        grScReqItem.setWorkflow(false);
         grScReqItem.autoSysFields(false);
 
        grScReqItem.work_notes = "RITM is closed incomplete as the requestor has been deactivated.";
        grScReqItem.state = "4";
        grScReqItem.update();
    }
})(current, previous);
12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

@sunil10 

can you try this

(function executeRule(current, previous /*null when async*/) {
    var grScReqItem = new GlideRecord('sc_req_item');
    grScReqItem.addEncodedQuery("cat_item=32524947c32b9a1062c17ebdc00131a5^stateNOT IN3,4,7^requested_for=" + current.sys_id);
    grScReqItem.query();
    while (grScReqItem.next()) {
        grScReqItem.setWorkflow(false);
        grScReqItem.autoSysFields(false);

        // Update work notes without including the user's name
        grScReqItem.work_notes = "RITM is closed incomplete as the requestor has been deactivated.";
        grScReqItem.state = "4";
        grScReqItem.update();
    }
})(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

@Ankur Bawiskar 

tried with your code state is getting updated only , then nothing happens worknotes also no updated

@sunil10 

I will recommend not using those 2 lines and let it be audited and let subsequent logic run whenever RITM state is getting updated.

This will help from audit point of view as well.

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