business rule in not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 12:24 AM
hi every one,
i want to abort the incident for particular group memebrs or admin
but it a not working for both the cases , its only working if i take only any one in the script , please correct the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 12:55 AM
Hi @Arjun Kumar Le1 ,
Have you remembered to make the business rule as "after"? Just tested below script which is working. Note that I have set the memberOf to SysId instead of name.
(function executeRule(current, previous /*null when async*/) {
if(!gs.getUser().isMemberOf('3D2831a114c611228501d4ea6c309d626d')) {
current.setAbortAction(true);
gs.addErrorMessage('You dont have the right to Create/Update P1 or P2 tickets');
}
})(current, previous);
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 01:00 AM
Hello @Arjun Kumar Le1 ,
Please use the below code :
if (!gs.getUser().isMemberOf('Display name of the group')||gs.hasRole('admin')) {
current.setAbortAction(true);
gs.addErrorMessage('You dont have the right to Create/Update P1 or P2 tickets');
//!gs.getUser().isMemberOf('280935791bde8190d7b0ea02604bcbb1')||
}
Please add the Display name of the group.
If the above answer resolve your issue, Please mark the solution as Accepted Solution and also mark it as Helpful.
Thank You.
Prathamesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 01:20 AM
The issue with your script is that you are using the logical OR operator (||) which means if any of the conditions are true, the entire condition becomes true. In your case, if the user is not a member of the specified group or if the user has an 'admin' role, the action will be aborted. This means that the action will be aborted for all users who are not members of the specified group, including admins. If you want the action to be aborted only for members of a specific group and admins, you should use the logical AND operator (&&) instead. Here is the corrected script: ```javascript (function executeRule(current, previous /*null when async*/ ) { // Add your code here if (gs.getUser().isMemberOf('280935791bde8190d7b0ea02604bcbb1') && !gs.hasRole('admin')) { current.setAbortAction(true); gs.addErrorMessage('You dont have the right to Create/Update P1 or P2 tickets'); } })(current, previous); In this corrected script: - The action will be aborted if the user is a member of the specified group and does not have an 'admin' role. - If the user is not a member of the specified group or if the user has an 'admin' role, the action will not be aborted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 01:38 AM
The issue with your script is the logical operator you are using. You are using the OR operator (||) which means if any of the conditions is true, the action will be aborted. In your case, if the user is not a member of the specified group OR if the user has an 'admin' role, the action will be aborted. This is why it's working for either case but not for both. You should use the AND operator (&&) to ensure that both conditions must be true for the action to be aborted. Here is the corrected script: ```javascript (function executeRule(current, previous /*null when async*/ ) { // Add your code here if (!gs.getUser().isMemberOf('280935791bde8190d7b0ea02604bcbb1') && gs.hasRole('admin')) { current.setAbortAction(true); gs.addErrorMessage('You dont have the right to Create/Update P1 or P2 tickets'); } })(current, previous); In this corrected script: - The action will be aborted only if the user is not a member of the specified group AND the user has an 'admin' role. - If the user is a member of the group but does not have an 'admin' role, or if the user has an 'admin' role but is not a member of the group, the action will not be aborted. - The error message will be displayed only when the action is aborted.