- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 09:54 PM
Hi,
I have a BR where I am trying to abort the submission if user has selected Yes is approval required but has not selected one of the approval.
User should either select user approval or group approval. If none is selected it will abort action.
Here is the code. BR is acting strange as I think my condition is not correct. It is only allowing submission when both checkboxes are checked.
Please guide.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ApprovalRequired = current.approval_required;
gs.info(ApprovalRequired);
var userApproval = current.user_approval;
var groupApproval = current.group_approval;
if(ApprovalRequired == 'yes' && (userApproval == '' || groupApproval == '')){
gs.addErrorMessage("Please select either User or Group Approval when Approval required is selected as Yes");
current.setAbortAction(true);
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 10:09 PM - edited 09-20-2023 10:50 PM
Hello @geet ,
You need to change
if(ApprovalRequired == 'yes' && (userApproval == '' || groupApproval == '')){
this statement as below
if(approval == 'Yes' && !(userApprove == true || groupApprove == true)){
You can achieve the same without using a script, please find below screenshots
Please mark my answer helpful, if it helps you
Thank you
Thank you
G Ramana Murthy
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 10:07 PM
script looks good.
are you checking correct choice value for yes?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 10:09 PM - edited 09-20-2023 10:50 PM
Hello @geet ,
You need to change
if(ApprovalRequired == 'yes' && (userApproval == '' || groupApproval == '')){
this statement as below
if(approval == 'Yes' && !(userApprove == true || groupApprove == true)){
You can achieve the same without using a script, please find below screenshots
Please mark my answer helpful, if it helps you
Thank you
Thank you
G Ramana Murthy
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 10:10 PM - edited 09-20-2023 10:17 PM
Hi @geet
I think your code is Ok.
Check backend value of Yes/No type is "Yes" or "No" / 'yes' or 'no'
For checkbox its "true" or "false"
Have updated if condition :
if(ApprovalRequired == 'Yes' && (userApproval == 'false' || groupApproval == 'false'))
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ApprovalRequired = current.approval_required;
gs.info(ApprovalRequired);
var userApproval = current.user_approval;
var groupApproval = current.group_approval;
if(ApprovalRequired == 'Yes' && (userApproval == 'false' || groupApproval == 'false')){
gs.addErrorMessage("Please select either User or Group Approval when Approval required is selected as Yes");
current.setAbortAction(true);
}
})(current, previous);
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 10:14 PM
Hi @geet ,
User Approval and Group Approval stores values as Boolean fields, So make these changes in your Condition:
if(ApprovalRequired == 'yes' && (userApproval == false || groupApproval == false))