List Control

sunny13
Giga Expert

Hi All,

I'm trying to hide "Edit" in the change task related list by using advance script in list control   for people without change_manager role and also there is an OR condition with respect to state.

Please review my code,

var answer;

if(gs.hasRole == "change_manager" ) ||   (parent.state=='3' || parent.state=='4' || parent.state=='-2' || parent.state=='-13' || parent.state=='-14' || parent.state=='2' || !parent.active;)

{

  answer=false;

}

else{

  answer=true;

}

But what happens is the EDIT button is not visible to anyone with any role except ADMIN i even revoked all changes but the EDIT button is missing from the related list.

But NEW button is visible to Users

find_real_file.png

Can someone help me debug this issue.

1 ACCEPTED SOLUTION

The change_task table should be editable to the user. Make sure the MPI


Change Manager has write access to the table.


View solution in original post

31 REPLIES 31

Deepa Srivastav
Kilo Sage

you should add AND condition if you want to show only to change manager in those states..Also hasRole syntax is wrong.. g_user.hasRole('change_manager').Also there is extra colon at the end..try below..And what you mean by   !parent.active




if(gs.hasRole('change_manager') &&   (parent.state=='3' || parent.state=='4' || parent.state=='-2' || parent.state=='-13' || parent.state=='-14' || parent.state=='2')


{


  answer=false;


}


else{


  answer=true;


}



and yes you can create a write ACL and add change_manager role in that.. it should work..



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


I understand the code is incorrect but my condition is the EDIT button should be visible to users during the above mentioned parent states and edit should be always visible to change_manager role.


zica
Giga Guru

SAjin,



If I gor it correctly, You want to hide the "Edit" button to all users that DON'T have the change_manager role and one of the role afore-mentionned. Thus, your condition is not correct.


It should look like the following   :


var answer = '';


if((g_user.hasRole('change_manager')) &&   (parent.state=='3')) { // add all the conditions as your requierement


  answer=true; // show the button because user has change_manager role


} else{


  answer=false; hide button cauz user do not have the requiered role


}


Hi AKB,



Condition 1 :I'm trying to show the EDIT button to users with MPI change Manager role


Condition 2 : when the parent state is one of them mentioned above i want to show all users the EDIT button not restricted to only users with MPI change manager role.



If any one condition matches the UI button should be visible


santoshsahoonis
Kilo Guru

Hello,



1. The visibility of 'Edit', 'New' etc UI Action on list are normally controlled by ACL's. You should use an ACL whenever possible. If you cannot fulfill your requirements via an ACL(very rare cases), you go for your approach.



2. Also, i can see that your script is incirrect. you dont use gs.hasRole() as the way you have.


Instead of gs.hasRole == "change_manager" , try gs.hasRole('change_manager');


GlideSystem - ServiceNow Wiki