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

Business Rule to change state doesn't work if state is "awaiting"

hugogomes
Giga Expert

Hi community,

I have created a Business Rule to change the state to "Reassigned" every time the assignment group changes.

It is a Before Rule for Insert and Update.

There are two things that I want for always to happen:

- if current.operation() == 'insert' and the user belongs to the same assignment group, the state can be everything;

- if current.operation() == 'update' and the assignment group changes the state is "Reassigned"

I did a basic rule but for some reason it doesn't work.

condition: current.assignment_group.changes()

script:

if(gs.getUser().isMemberOf(current.assignment_group) && current.operation() == 'insert'){

return;

}

else{

current.state = -5;

}

For some reason if I try to pass the incident in an awaiting state, it doesn't work the first time.

Also, the condition to check if the user belongs to that group is not doing anything, because I've tried to put the state in a specific state.

Any ideas in how I can solve this?

Thank you very much

1 ACCEPTED SOLUTION

hugogomes
Giga Expert

It turns out, it was a very basic thing...



It had to do with the order of the Business Rule, I've changed the order to a higher number and it works perfectly.



Thank you for you help!


View solution in original post

8 REPLIES 8

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Hugo,



I don't see any issue in your code. Can you please put few log statements and check once.


I tested, This code is working perfectly, may be Reassigned value might be wrong.


find_real_file.png


Yes, it should work but it doesn't change the state from awaiting to Reassigned.



The funny thing is that, in the work notes it shows correctly... And I don't know why...



The second if condition, I actually get the correct state in the work notes, but the incident state did not changed.



Here's my code:



if(gs.getUser().isMemberOf(current.assignment_group) && current.operation() == 'insert'){


//return;


  current.work_notes = "current assignment group if user belongs to group: " + current.assignment_group.getDisplayValue();


}


if (current.assignment_group.changes() && ((current.state.changesTo('3') || current.state.changesTo('0') || current.state.changesTo('5')))){


  // if the assignment group changes and the state changes to an awaiting state


  current.work_notes = "State changed";


  current.state = -5;


  current.u_user_feedback_expiration = "";


  current.work_notes = "State changed to "+ current.state.getDisplayValue();


}


else{


current.state = -5;


  current.work_notes = "current assignment group if does not belong to group: " + current.assignment_group.getDisplayValue();


}


I keep having the same problem.



If I, before saving, change the state it will not update the value. But the strange part is that the value in current.state is correct, it is showing as "reassigned".



I also tried to do something stupid like, in the same condition adding the following:



current.state = -5;


current.state = '-5';


current.setDisplayValue('state','Reassigned');



None of these worked... Not even these 3 at the same time



Any Idea how I can correct this?