Populate custom field from incident state field

Saranya2
Tera Contributor

Hi All,

 

I have a custom field "incident state"(choice) on escalation log table, if incident state is updated on incident table, i need to update the "incident state"(choice) field

I have written after insert/update BR, but it is not setting the value, Not able to debug it, can anyone please suggest. 

For the below code if I checked log, i am getting the value.

 

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

 

    // Add your code here

    var inc_state = new GlideRecord('on_call_escalation');  

    inc_state.query('source',current.sys_id);

    inc_state.query();

    if(inc_state.next()){

        inc_state.u_incident_state = current.state;

        gs.log("esc inc state"+ inc_state.u_incident_state);

        inc_state.update();

    }

})(current, previous);

 

Thanks,

Saranya

2 ACCEPTED SOLUTIONS

Anirudh Pathak
Mega Sage

Hi @Saranya2,

Please update your code as below -

 

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

    // Add your code here
    var inc_state = new GlideRecord('on_call_escalation');  

    inc_state.addQuery('source',current.sys_id);

    inc_state.query();

    if(inc_state.next()){

        inc_state.u_incident_state = current.state;

        gs.info("esc inc state"+ inc_state.u_incident_state);

        inc_state.update();

    }
})(current, previous);

 

View solution in original post

AshishKM
Kilo Patron
Kilo Patron

Hi @Saranya2 , 

Please check the code, you have 2 query statement and the second one is getting all data from On Call Escalation table.

Due to If condition, result set is iterating for first record only  which may ( or may not ) be  same Incident record.

 

replace below query with addQuery

inc_state.query('source',current.sys_id);

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

View solution in original post

2 REPLIES 2

Anirudh Pathak
Mega Sage

Hi @Saranya2,

Please update your code as below -

 

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

    // Add your code here
    var inc_state = new GlideRecord('on_call_escalation');  

    inc_state.addQuery('source',current.sys_id);

    inc_state.query();

    if(inc_state.next()){

        inc_state.u_incident_state = current.state;

        gs.info("esc inc state"+ inc_state.u_incident_state);

        inc_state.update();

    }
})(current, previous);

 

AshishKM
Kilo Patron
Kilo Patron

Hi @Saranya2 , 

Please check the code, you have 2 query statement and the second one is getting all data from On Call Escalation table.

Due to If condition, result set is iterating for first record only  which may ( or may not ) be  same Incident record.

 

replace below query with addQuery

inc_state.query('source',current.sys_id);

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution