Help with Business Rule on Change Request to Validate Approvers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2022 09:45 AM
On a Change Request form, I have a custom field (reference to sys_user) to add an additional Business Approver.
I want to write a business rule to prevent the Assigned To person from being the same as this Business Approver.
The field name is u_business_approval.
I created a BR, but it will simply not run. After 5 hours of going crazy, I am hoping someone can point me in the right direction.
Business Rue Name: Validate Approvers
Advanced = True
When to run: Before - Update
Order : 100
Condition: (current.state.changesTo(-3) && current.type=='normal') || (current.state.changesTo(-4) && current.type=='normal')
SCRIPT:
(function executeRule(current, previous /*null when async*/ ) {
var assignedTo = g_form.getValue("assigned_to");
if ((assignedTo == g_form.getValue('u_business_approval'))
// current.setAbortAction(true);
alert("Business Approver cannot be Assigned To");
current.state = -5; //check state value
current.approval = 'not requested'; //remove it if you don't want to set approval
}
})(current, previous);
Many thanks for any assistance. Mark S.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2022 09:51 AM
Hi,
g_form is a client side code that only runs on the form, and you are using a business rule , which runs on server side.
To access the data on server side you can use current object.
Be sure this is a before BR
(function executeRule(current, previous /*null when async*/ ) {
var assignedTo = current.assigned_to;
if (assignedTo == current.u_business_approval)
gs.addInfoMessage("Business Approver cannot be Assigned To");
current.state = -5; //check state value
current.approval = 'not requested'; //remove it if you don't want to set approval
}
})(current, previous);
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 04:39 PM
Thanks for the reply. Unfortunately the BR does not run when I add the condition:
(current.state.changesTo(-3) && current.type=='normal')
Active=True
When to run: before + update
Order - I have tried variaous orders, from 99 to 999
Advanced = true
Condition = (current.state.changesTo(-3) && current.type=='normal')
(function executeRule(current, previous /*null when async*/ ) {
var assignedTo = current.assigned_to;
if (assignedTo == current.u_business_approval){
gs.addInfoMessage("Business Approver cannot be Assigned To");
current.state = -5; //check state value
current.approval = 'not requested'; //remove it if you don't want to set approval
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 12:36 AM
Hi,
For the condition can you use the Filters Conditions OOB.
And then add logs to see whether the script runs or not.
-Anurag

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 12:41 AM
Can you try below
Remove everything from condition & try below
(function executeRule(current, previous /*null when async*/ ) {
if(current.type=='normal')
{
var assignedTo = current.assigned_to;
if (assignedTo == current.u_business_approval){
gs.addInfoMessage("Business Approver cannot be Assigned To");
current.setAbortAction(true);
}
}
})(current, previous);