
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2023 01:34 AM
Hello All
I have the need to hide certain business rules outside of a specific user role. So I have a True/False field in the sys_script table called "u_ebonding_business_rule".
If this field is set to true, those records can only be seen by users with the role "ebonding_admin".
I have created a query business rule with the code below but it doesn't work..
(function executeRule(current, previous /*, gs*/ ) {
// Define the name of the role that can view the business rule
var allowedRole = "ebonding_admin";
// Check if the business rule has the 'ebonding business rule' flag set to true
var ebondingFlag = current.getValue("u_ebonding_business_rule");
if (ebondingFlag == true) {
// Get the current user's role(s)
var currentUser = gs.getUser();
var userRoles = currentUser.getRoles();
// Check if the user has the allowed role
if (userRoles.indexOf(allowedRole) == -1) {
// If the user does not have the allowed role, restrict visibility
current.setDisplay(false);
gs.info("Business rule " + current.name + " hidden from non-" + allowedRole + " users.");
}
}
})(current, previous);
Can someone help me ? 🙂
Thanks
Jérôme
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2023 01:46 AM - edited 05-09-2023 02:37 AM
Hi @Jerome MAISETTI ,
Please try with this version of your business rule:
(function executeRule(current, previous /*, gs*/ ) {
// Define the name of the role that can view the business rule
var allowedRole = "ebonding_admin";
// Get the current user's role(s)
var currentUser = gs.getUser();
var userRoles = currentUser.getRoles();
// Check if the user has the allowed role
if (userRoles.indexOf(allowedRole) == -1) {
// If the user does not have the allowed role, restrict visibility
current.addEncodedQuery('u_ebonding_business_rule=false');
gs.info("Some Business rules are hidden for non-" + allowedRole + " users.");
}
})(current, previous);
If my answer has helped with your question, please mark it as correct and helpful
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2023 01:44 AM
You can achieve the same thing using ACL by mentioning your condition as well roles.
Please check this Link
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2023 01:46 AM - edited 05-09-2023 02:37 AM
Hi @Jerome MAISETTI ,
Please try with this version of your business rule:
(function executeRule(current, previous /*, gs*/ ) {
// Define the name of the role that can view the business rule
var allowedRole = "ebonding_admin";
// Get the current user's role(s)
var currentUser = gs.getUser();
var userRoles = currentUser.getRoles();
// Check if the user has the allowed role
if (userRoles.indexOf(allowedRole) == -1) {
// If the user does not have the allowed role, restrict visibility
current.addEncodedQuery('u_ebonding_business_rule=false');
gs.info("Some Business rules are hidden for non-" + allowedRole + " users.");
}
})(current, previous);
If my answer has helped with your question, please mark it as correct and helpful
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2023 02:06 AM
thaaaaaaanks a lot! This did the trick 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2023 02:27 AM
I would suggest you to look a bit more into the script accepted.
This is very bad practice
Query business rules doesnt have access to anything else than queries
So current.getValue() will always return undefined
Just a heads up