Abort action based on some value.

asasas
Kilo Contributor

I have a field name "counter", which count the number of times a task is reassigned to another person using "Assigned to" field.

Based   upon counter value (say 3) i.e. if same task is reassigned more than 3 times to another person, it should not allow to change.

I got answer where in database it is not allowing to change (once I refresh the page) but in "Incident form " it is allowing i.e. it is reassigned to another person in "Assigned to" field.
I want to stop user from changing in "Assigned to" field also   .

I am using Business rule and my code is :

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

  var counter;

  if(current.assignment_group.changes())

  {

  counter=current.u_counter=0;

    }

else if(current.assigned_to.nil())

  {

          current.u_counter=0;

    }

else if(current.u_counter>3)

  {

                gs.addInfoMessage("You excede more than 3 time   ! Now you cannot changed Assigned to field");

                current.state=previous.state;  

                gs.setValue('assigned_to', current.state);

            current.setAbortAction(true);  

            gs.setRedirect(current.state);  

  }

  else

  {

  current.u_counter += 1;

  }

})(current, previous);

Please help.

9 REPLIES 9

asasas
Kilo Contributor

Just have a look.Capture.PNG





I want my assigned to field in form should not change once counter is set to 3.
In form I can switch, but in database it is working.
My job is to stop changing from from itself.


asasas
Kilo Contributor

Code is working fine,   but my requirement is to stop user from changing "assigned to " field in the form. It should not allow user to change the name of "assigned to" in the Incident form.


Geoffrey2
ServiceNow Employee
ServiceNow Employee

That's exactly what the above code does.


asasas
Kilo Contributor

But in Incident form user can assigned to another person using look up.In   form it is taking , but



My task is to stop user from further selecting person from "Assignment to" field in the Incident management , i.e once the name is selected user cannot change futher( like make it read only field type) with last assigned user name written in it.


Geoffrey2
ServiceNow Employee
ServiceNow Employee

Then use the first Business Rule with a UI Policy.


Condition: Counter 'greater than' 3


Action: Make Assignment group read-only.