- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 05:46 PM
Hi all,
I want to display error message on top of the REQ form when any users who are not part of the specific assignment groups opens a specific REQ record. I am thinking of using Business rule with when to display but it is displaying message for all users.
I have worked out to control the view on RITM via before query business rule but we want to display the REQ record and also show the error message if they open the record.
Below is the business rule configuration:
When: Display
Filter: Short Description is Non-Imp Requests
Script:
(function executeRule(current, previous /*null when async*/ ) {
if (!gs.getUser().hasRole("admin") || !gs.getUser().isMemberOf('fa3995dcdb694c50c317f6fcbf9619d8') || !gs.getUser().isMemberOf('c85cadc5db590c1064947f69bf9619a0')) {
gs.addErrorMessage("You do not have permission to view RITM record for this REQ.");
}
})(current, previous);
Please let me know what is wrong with this script or is there a better way to do it.
Thank you
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2022 06:45 AM
Hi,
I hoped my above reply was at least Helpful.
I would test this yourself.
This would be the opposite of what I mentioned above, in detail.
The user would see the error message if they are not admin AND they aren't in group 1 AND they aren't in group 2. So if all 3 of those are true, then they see the message.
- So admin wouldn't see it.
- Members of group 1 wouldn't see it
- Members of group 2 wouldn't see it
If this is your desired outcome, then you're good to go.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 05:53 PM
Hello,
Per what you said in your post, your script doesn't correlate with that...?
You're going to show the message if the user is not admin OR if the user is not a member of group1 OR if the user is not a member of group2.
Please review and correct your if statement accordingly.
Not sure where the "not an admin" condition came in to play, as you didn't say that in your post, but it's there in your script.
You'd also want to show that when they are NONE of those things, so you'd need to use (AND) && and not (OR) ||. Otherwise, the very first one of those conditions, if it results to true, it's going to show the error message.
The way you currently have it built, this would be the scenario run-down:
- So if they aren't admin - error message
- If they are admin, but not in group 1 - error message
- If they are admin, but in group 1, but not group 2 - error message
- If they are admin, but in group 1, and in group 2 - then no error message
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 07:27 PM
Thank you for the explanation
(function executeRule(current, previous /*null when async*/ ) {
if (!gs.getUser().hasRole("admin") && !gs.getUser().isMemberOf('fa3995dcdb694c50c317f6fcbf9619d8') && !gs.getUser().isMemberOf('c85cadc5db590c1064947f69bf9619a0')) {
gs.addErrorMessage("You do not have permission to view the Requested Item.");
}
})(current, previous);
I have replaced the OR|| operator with AND && so would I be correct in saying
- If they are not admin - error message
- If they are not part of group 1 - error message
- If they are not part of group 2 - error message
Let me know.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2022 06:45 AM
Hi,
I hoped my above reply was at least Helpful.
I would test this yourself.
This would be the opposite of what I mentioned above, in detail.
The user would see the error message if they are not admin AND they aren't in group 1 AND they aren't in group 2. So if all 3 of those are true, then they see the message.
- So admin wouldn't see it.
- Members of group 1 wouldn't see it
- Members of group 2 wouldn't see it
If this is your desired outcome, then you're good to go.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!