After business rule to update state field value based on incident state

Community Alums
Not applicable

I need an after business rule to update state field based on incident state (incident_state) value on the incident table

4 REPLIES 4

Manmohan K
Tera Sage

Hi @Community Alums ,

 

You can write a before business rule with below code

 

if(current.incident_state==30){
current.setDisplayValue('state','Work In Progress');
}
else if(current.incident_state==70){
current.setDisplayValue('state','Closed Complete');
}
else
current.setDisplayValue('state','Open');
}

 

 

Community Alums
Not applicable

Hi @Manmohan K,

 

Thanks for your response.

 

I tried this but its not working, I feel there must be something blocking. There's one OOB BR which I disabled, but its not making any difference. Before disabling this it was taking incident_state values and displaying the numeric values on state field

RJ8_0-1684754757308.png

 

Amit Gujarathi
Giga Sage
Giga Sage

Hi @Community Alums ,
I trust you are doing great.

 

  1. In the "When to run" section, select "After" for the timing.
  2. In the "Advanced" section, add a script to update the "state" field based on the "incident_state" value.

Here's an example script that you can use:

(function executeRule(current, previous) {
  var incidentState = current.incident_state;
  var stateToMap;

  // Define the mapping based on the incident_state value
  switch (incidentState) {
    case '10':
    case '15':
    case '20':
    case '40':
    case '45':
    case '47':
    case '50':
    case '55':
    case '57':
    case '60':
      stateToMap = '2'; // '2' represents 'Open' state
      break;
    case '30':
      stateToMap = '3'; // '3' represents 'Work In Progress' state
      break;
    case '70':
      stateToMap = '7'; // '7' represents 'Closed Complete' state
      break;
    default:
      stateToMap = current.state; // Keep the current state if no mapping is found
      break;
  }

  // Update the state field with the mapped value
  current.state = stateToMap;
})(current, previous);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Community Alums
Not applicable

Hi @Amit Gujarathi Thanks for your response.

I tried your script, it's not working too.