After business rule to update state field value based on incident state
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2023 04:00 AM - edited ‎05-22-2023 10:12 AM
I need an after business rule to update state field based on incident state (incident_state) value on the incident table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2023 04:10 AM - edited ‎05-22-2023 04:11 AM
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');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2023 04:26 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2023 05:30 AM
Hi @Community Alums ,
I trust you are doing great.
- In the "When to run" section, select "After" for the timing.
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2023 06:02 AM