The CreatorCon Call for Content is officially open! Get started here.

Updating a field using an After Business rule when previous value is the same

mohcine elbah
Tera Contributor

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 😀

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

@mohcine elbah 

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?

AnkurBawiskar_0-1745935352249.png

 

Create an incident state model 

Incident Management State Model 

Life cycle of an Incident 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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

mohcineelbah_0-1745936462538.png

 

I got the same behaviour on another client's instance.

@mohcine elbah 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Robert H
Mega Sage

Hello @mohcine elbah ,

 

Please change your Business Rule as shown below. No script required.

RobertH_0-1745936777486.png

 

Regards,

Robert