State and Incident State sync issue

Bhagya
Tera Contributor

Hi All,

I have a custom Before Update BR as below:
When to Run : u_strike_counter = 4

/**
 * Incident state is set to resolved when 3 strike counter changes to 4
 */
(function executeRule(current, previous /*null when async*/ ) {
    current.state = global.IncidentState.RESOLVED;
    current.resolved_by = gs.getUserID();
    current.close_code = 'No resolution provided';
    current.close_notes = gs.getMessage('pmi_gv.incident.3_strike_close_notes', current.short_description);
})(current, previous);

But When incident is resolved, the state field is getting updated to Resolved but the Incident State field is still in progress. The OOTB state to incident state sync BR is not working.
4 REPLIES 4

Brad Bowman
Kilo Patron

I would use current.state = 6; in this script to trigger the state sync OOTB BR.

But as per the client we should not hardcode the value

AnkaRaoB
Kilo Guru

Hi @Bhagya ,

 

The issue occurs because the state is being set in a Before Update BR, which bypasses the OOTB incident state sync logic. Move the logic to an After Update BR or explicitly set both state and incident_state. Best practice is to update the state in an After Update BR and let OOTB sync handle the incident state


If my response helped mark as helpful and accept the solution

Thanks,

AnkaRao

Chaitanya ILCR
Mega Patron

Hi @Bhagya ,

try setting the order of the BR to less than 0 (like -1 or -100)

 

or change the BR to After or Async with current.update()

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya