Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Updating state before insert of record not working

Anna_Servicenow
Tera Guru

I have the below script where i am trying to update the state of record from open > duplicate request before insert in BR. I have below script but its not working.

1) should I make it After insert ?

2) Is the script wrong?

 

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

    var caseid= current.case;
    var amount = current.amount;
    var serv_type = current.type_of_service;

    var gr = new GlideRecord('x_inffr_task');

    gr.addQuery('case', caseid);
    gr.addQuery('amount', amount);
    gr.addQuery('type_of_service', serv_type);
    gr.addQuery('sys_created_on', '>', gs.daysAgo(30));
    gr.query();
    gr.next();
    while (gr.next()) {
       

        current.state = '8';
        }
    }
1 ACCEPTED SOLUTION

Anna_Servicenow
Tera Guru

The script worked with before insert

View solution in original post

11 REPLIES 11

Community Alums
Not applicable

Hi @Anna_Servicenow 

Try using current.update() after you set the state as 8, here is the code below.

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

    var caseid= current.case;
    var amount = current.amount;
    var serv_type = current.type_of_service;

    var gr = new GlideRecord('x_inffr_task');

    gr.addQuery('case', caseid);
    gr.addQuery('amount', amount);
    gr.addQuery('type_of_service', serv_type);
    gr.addQuery('sys_created_on', '>', gs.daysAgo(30));
    gr.query();
    gr.next();
    while (gr.next()) {
        current.state = '8';
       current.update();
        }
    }

 

Thanks,

Let me know if that worked.

 

Anna_Servicenow
Tera Guru

The script worked with before insert