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

Hello @Robert H ,

I have client related condition, so I should only update to Work In progress when certain conditions are satisfied, I cannot check these condition using no code, I have to write a script that checks these conditions

Hello @mohcine elbah ,

 

Ok, then use a script. The important thing is that you set both the State and Incident state fields to In progress. That's why your original solution does not work.

 

Regards,

Robert

I tried this script now, setting BOTH incident state and state to Work In Progress, but unfortunatly both fields are not set to work in progress

(function executeRule(current, previous /*null when async*/) {

	if(current.state == 6){
		current.state = 2;
		current.incident_state = 2;
		current.setWorkflow(false);
		current.update();
	}

})(current, previous);

Your code works in my PDI:

 

	// Add you code here
	if(current.state == 6){
		current.state = 2;
		current.impact = 1;
		current.setWorkflow(false);
		current.update();
		gs.addInfoMessage('BR: Set state to: ' + current.state);
	}

I do have to set the 'Resolution code' and 'Resolution notes' for the update to work.

 

Seems you have something else responsible for what you see.

Hello @Bert_c1 

Have you used this code in an AFTER business rule ?