Script for List Control (hide 'New' button)

Leonel Sandroni
Tera Guru

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

LeonelSandroni_0-1688562832928.png

 

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:

LeonelSandroni_1-1688563604207.png

 

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.

LeonelSandroni_3-1688564208540.png

 

Any suggestion?

 

Thank

 

4 REPLIES 4

Manmohan K
Tera Sage

Hi @Leonel Sandroni 

 

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;

 

 

 

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

Manmohan K
Tera Sage

@Leonel Sandroni 

 

Yes, but use it with right object

Try with parent.canCreate() or current.canCreate() depending on which table ACL you need to be validated

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 ;