The CreatorCon Call for Content is officially open! Get started here.

canWrite() function for parent records

Leonel Sandroni
Tera Guru

Hi there,

 

I'm trying to restric ACLs permissions for Demand RIDACs items according to demand record permissions. I need to use the canWrite() function and it should look the parent demand record. I have builded a script but it doesn't work

 

var answer=false;

    // Check if current user can edit parent

    if (parent.canWrite()) 
      
       {
        answer=true;
      }

 

 

Do you know what is wrong?

Thanks

1 ACCEPTED SOLUTION

Leonel Sandroni
Tera Guru

Ok, I have found the solution. First you need to refert to the parent record with getRefRecord() and then check permissions with canWrite so:

var parent= current.parent.getRefRecord();
      answer = parent.canWrite();

 

it should work

View solution in original post

9 REPLIES 9

@Leonel Sandroni Can you check if the record has a parent assigned to it?

Yes, it has a parent record

LeonelSandroni_0-1690311773359.png

 

Also I have checked the write ACLs in dmn_demand (parent table) and it seems to be right

Sonam Tiwari
Tera Guru

@Leonel Sandroni ,

 

The script looks correct. Just adding some lines below so that you can add logs and check

var answer = false;
if (current.parent) {
gs.log("Parent exists. Parent canWrite(): " + current.parent.canWrite());
if (current.parent.canWrite()) {
answer = true;
gs.log("User can edit parent demand record.");
}
} else {
gs.log(" Parent record not found or parent field is empty.");
}


In case the logs don't help and everything seems right. Please enable 'Debug security rules' and check whether there are any other ACLs that match and are restricting the permissions.

I have debugged the acls and I have found this script condition is the problem

Leonel Sandroni
Tera Guru

Ok, I have found the solution. First you need to refert to the parent record with getRefRecord() and then check permissions with canWrite so:

var parent= current.parent.getRefRecord();
      answer = parent.canWrite();

 

it should work