Script for List Control (hide 'New' button)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 08:22 AM - edited 07-05-2023 08:23 AM
Hi there!,
I'm looking for a solution to accomplish some requirements customer has asked me for. They want to block demand items edition according next conditions:
- Admin, PPS_Admin, Members of assigned group (in the demand, not in the item) and assigned demand manager, can create or edit demand items (task, RIDAC, etc)
- Any another user can't edit or create this items
let's take demand task as an example. I would like to hide/show 'New' buttón to meet the goal. I thought that modifying the existing ACLs with an script would do it...
...and it works. If any user who does not comply with the permissions will try to create a demand task would not be able to submit the demand task. You can see:
Ok this solution will work but the problem is, as a mentioned above, I would like meet the goal directly hiding/showing the 'New' button and with the ACL I can't do it.
I have tried with script in 'omit new condition' in list controls but I haven't had good results 😞
Is it possible to do it only with ACLs or should I work with script in the list control? Could the function 'canCreate()' work? With the same ACL script in the list control it doesn't work.
Any suggestion?
Thank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 09:00 AM - edited 07-05-2023 09:02 AM
You should be using omit new condition for showing/hiding new button on related list
You can use below script for it (modify roles and field names wherever required)
var currentUser = gs.getUser(); // Get the current user
var isAllowed = false; // Initialize the flag for permission
if (currentUser.hasRole('admin') || currentUser.hasRole('PPS_Admin')) {
isAllowed = true;
} else {
// Get the assigned group from the Demand form (assuming it's stored in a field called 'assigned_group')
var assignedGroup = parent.assigned_group;
if (assignedGroup && currentUser.isMemberOf(assignedGroup)) {
isAllowed = true;
}
// Get the assigned demand manager from the Demand form (assuming it's stored in a field called 'demand_manager')
var demandManager = parent.demand_manager;
if (demandManager && currentUser.getID() === demandManager) {
isAllowed = true;
}
}
isAllowed;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 09:23 AM
Thanks @Manmohan K for the script!!!
let me ask you...Do you know if the function "canCreate()" could be able to work? I have the proper ACLs and I think maybe with this function I could build a shorter script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 09:29 AM
Yes, but use it with right object
Try with parent.canCreate() or current.canCreate() depending on which table ACL you need to be validated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 11:23 AM
Ok, I'll try with something like this:
var answer ;
if (current.canCreate()) { //Do not remove the 'New' button
answer = false ;
}
else { //Remove the 'New' button
answer = true ;
}
answer ;