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-17-2022 08:56 AM
Thanks for the replies , after much hairpulling, this is what I ended up with. The main issue I had as making sure the form didnt update the state and approval fields when I hit 'submit for approval'. Any enhancement/ideas for improvement appreciated.
The issue I had was that the state always went to 'Assess', so I had to add code to clear the values.
Would be great if there was a way to reload the form, and set it back to the previous values - ie back tot the state it was before attempting to update the form. Make sense?
Condition: current.state.changesTo(-3) || current.state.changesTo(-4) || current.state.changesTo(-1) || current.state.changesTo(-3) || current.state.changesTo(-2)
When to run: Before, Update
(function executeRule(current, previous /*null when async*/ ) {
var assignedTo = current.assigned_to;
if ((assignedTo == current.u_business_approval) || (assignedTo == current.u_business_approval_2)) {
current.setAbortAction(true);
var message1 = '* Business Approver cannot be Assigned To *';
var message2 = message1.fontcolor("red");
gs.addInfoMessage(message2);
//g_form.clearValue('assigned_to');
current.state = -5; //check state value
current.assigned_to = "";
current.approval = 'not requested'; //remove it if you don't want to set approval
}
})(current, previous);