Updating a field using an After Business rule when previous value is the same
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2025 05:33 AM - edited 04-29-2025 05:33 AM
Hello,
While I was scripting in a business rule I came across this issue. I am testing through my personal instance, and I am sure there is no custom scripting causing the issue.
Here is the situation : I have an After Business Rule which triggers when the state field in Incident table changes to Resolved (6), the script of the Business rule changes the state to Work in progress (2).
The issue is : If the initial state is per example New (1) and then I change manually the state to Resolved (6) this triggers the Business Rule, and It changes the state to Work in Progress (2), until here all is working as expected. BUT, if the inital state is Work in Progress (2) and I change manually the state to Resolved (6) this triggers the Business rule, but it doesn't update the state's value to Work in progress (2) as expected, the state stays Resolved (6) (Even tough all the other fields are updated as programmed in the business rule)
(function executeRule(current, previous /*null when async*/) {
if(current.state == 6){
current.state = 2;
current.impact = 1;
current.setWorkflow(false);
current.update();
}
})(current, previous);
Note : This issue can be fixed if I put a current.update() just before current.state = 2; and keeping the last current.update(), this is not a good solution.
Note 2 : I have tried changing the order of the business rule to 10000 and removing setWorkflow(false) and setAbortAction(true), all these didn't work.
Appreciate if someone has a better solution
Thank you 😀
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2025 07:02 AM
any state model is blocking the state transition from 6 to 2?
Your business rule tries to update state but is blocked by state model and hence it doesn't update the state but updates other fields
Did you check that state model?
Create an incident state model
Incident Management State Model
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2025 07:22 AM
Thank for your reply @Ankur Bawiskar
I check in sys_state_model table and couldn't find any record related to incident table, I am using a new Personal instance, nothing custom is developped on it
I got the same behaviour on another client's instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2025 07:28 AM
Seems some other business rule is blocking.
check the approach shared by @Robert H
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2025 07:26 AM
Hello @mohcine elbah ,
Please change your Business Rule as shown below. No script required.
Regards,
Robert