How to hide New/Edit button on related list based on value of parent field?

swathigangadhar
Tera Expert

ct.png

When RITM is in 'waiting_for_approval' state, I need to hide new and edit button, Am writing below script, Which is resulting in hiding buttons in all state.

I tried using parent.stage='waiting_for_approval' and parent.stage=='waiting_for_approval'.

please suggest me what am doing wrong?

script:

----------------

var answer;

if((parent.assigned_to!=gs.getUserID()) || (!parent.active)||(parent.stage='waiting_for_approval')){

answer=true;

}

else{

answer=false;

}

1 ACCEPTED SOLUTION

OK. Please update your code as below:



Script:



if(parent.stage=='waiting_for_approval')


{


  answer=true;


}


else if(parent.stage!='waiting_for_approval' && parent.assigned_to==gs.getUserID())


  {


  answer=true;


  }



It's working for me on my Personal instance.Please find the scenarios I have tested as per your requirement.



Scenario 1: When the Stage of RITM is Waiting For Approval irrespective of Assigned To, the New button is made hidden irrespective of Assigned To. Please see the screen shot below:



find_real_file.png



Scenario 2: When the Stage is Not Waiting For Approval and say any other stage and now we are checking if the Assigned to User is same as Logged in User or not. If they are same we are again hiding the New Button. Please see the screenshot below:



find_real_file.png



I have logged in as System Administrator which is same as Assigned To so the New button is now not visible.



Scenario 3: Now when the stage is anything except Waiting for Approval and Assigned To is also not same as Logged in User which is your Third scenario so the New button would again be visible as shown below:



find_real_file.png



In the above screen shot I have again logged in as System Administrator and Assigned To is Abel Tuter, so now the New Button is visible.



Hope this helps.Mark the answer as correct/helpful based on impact.



Regards,


Shloke





Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

12 REPLIES 12

OK. Please update your code as below:



Script:



if(parent.stage=='waiting_for_approval')


{


  answer=true;


}


else if(parent.stage!='waiting_for_approval' && parent.assigned_to==gs.getUserID())


  {


  answer=true;


  }



It's working for me on my Personal instance.Please find the scenarios I have tested as per your requirement.



Scenario 1: When the Stage of RITM is Waiting For Approval irrespective of Assigned To, the New button is made hidden irrespective of Assigned To. Please see the screen shot below:



find_real_file.png



Scenario 2: When the Stage is Not Waiting For Approval and say any other stage and now we are checking if the Assigned to User is same as Logged in User or not. If they are same we are again hiding the New Button. Please see the screenshot below:



find_real_file.png



I have logged in as System Administrator which is same as Assigned To so the New button is now not visible.



Scenario 3: Now when the stage is anything except Waiting for Approval and Assigned To is also not same as Logged in User which is your Third scenario so the New button would again be visible as shown below:



find_real_file.png



In the above screen shot I have again logged in as System Administrator and Assigned To is Abel Tuter, so now the New Button is visible.



Hope this helps.Mark the answer as correct/helpful based on impact.



Regards,


Shloke





Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Antonio42
Kilo Guru

guys, I need to hide the task_ci (affected Cis) button into the change_task, is there anything to use something like sub_parent?

I got it, you need to use parent.parent, thanks!