Abort action based on some value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2016 02:38 AM
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.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2016 03:05 AM
This assumes that your condition is: current.assigned_to.changes()
(function executeScript(current) {
if (current.assignment_group.changes() || current.assigned_to.nil()) {
current.u_counter = 0;
}
else {
if (current.u_counter > 3) {
current.setAbortAction(true);
gs.addInfoMessage("This task has been reassigned more than 3 times. You cannot reassign it again.");
} else {
current.u_counter++;
}
}
})(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2016 03:16 AM
Dear Geoffrey
My problem is I have to stop user from further selecting/changing (not allowing more than 3 times) in the assigned to field
Code is working fine, but i have to stop user from further reallocating to another person.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2016 03:30 AM
That's exactly what the code does.
But you should really be handling it with a Client Script on the form. That Business Rule should stay there in case the Incident is updated from the List View.
To handle it on the Client-side, I would create a display Business Rule:
g_scratchpad.counter = current.u_counter;
g_scratchpad.assignment_group = current.assignment_group;
Then a Client Script that executes when Assigned to changes
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || oldValue == newValue)
return;
g_form.hideFieldMsg('assigned_to', true);
if (newValue == '')
return;
var counter = parseInt(g_scratchpad.counter);
var isSameGroup = g_scratchpad.assignment_group == g_form.getValue('assignment_group');
if (isSameGroup && counter > 3) {
g_form.setValue('assigned_to', oldValue);
var msg = 'This task has been reassigned more than 3 times. You cannot reassign it again.';
g_form.showFieldMsg('assigned_to', msg, 'error');
}
}
The above Business Rule will then increment the counter when the form is saved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2016 04:25 AM
I think you code will work, but i new to SN, so i am not getting where to write this code.
2nd code i am writing in client script but i am not getting where to write those two line of code(1st code)