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

User Criteria not working

snehalkhare
Kilo Guru

Hi All,

I have a User criteria with following conditions in the Available for related list:

if(gs.hasRole('rolename')){

return true;

}

else if(gs.isMemberOf('grp_name')){

return false;

}

else {

return false;

}

 

When testing its not working properly, first I added the role used in condition to the user then that particular category was visible - correct working. Then removed the role and added user to the group, the category is still visible.It should not be visible- not working.

I have tried clearing cache, and when logs were added to the user criteria noticed that it only works first time when impersonated by the user. 

How to fix this?

Regards,

Snehal K

 

 

1 ACCEPTED SOLUTION

snehalkhare
Kilo Guru

Hi All,

Thanks for the advice. After further testing found that it was a cache issue. The script worked properly,checked by logs.

After clearing the cache it worked properly

 

Thanks,

Snehal Khare

View solution in original post

12 REPLIES 12

Jaspal Singh
Mega Patron
Mega Patron

Try using below.

if(gs.getUser().hasRole('rolename')){

return true;

}

else if(gs.getUser().isMemberOf('grp_name')){

return false;

}

else {

return false;

}

Hi Jaspal,

 

for else part I have used gs.getUser.isMemberOf('group_name') only. Missed getuser in question.

I have tried gs.getUser().hasRole('role_name') as well.

It didn't solve the issue.

Thanks

 

For role gs.hasRole('role_name') & for group gs.getUser().isMemberOf('groupname') should work. can you something like below.

answer=applyrestriction();
function applyrestriction()
{
if(gs.hasRole('rolename')){
return true;
}
else if(gs.getUser().isMemberOf('grp_name')){
return false;
}
else {
return false;
}
}

 

As return is being used without any function.

Not working