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

Am getting conflict here, bcz when I am logged in user and assigned to me, and if its in waiting_for_approval state, then am able to see buttons.


But i need irrespective of whom it is assigned(even for logged in user also), it should hide when RITM is in waiting_for_approval.


Ok. Simply remove the first condition where you are checking the Assigned To Validation and other also if you just want to check for Waiting for Approval stage as mentioned below:



if(parent.stage=='waiting_for_approval')


  {


  answer=false;


  }


else


  {


  answer=true;


    }



Tested on my personal instance and it's working fine. Kindly check from your end too.



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

but i want to check this also, when RITM is assigned to logged in user and it is not in waiting_for_approval, then need to hide else need to show.


I don't think it is possible to implement.Because in one condition you want to Hide the Button when the stage is Waiting for Approval and then again the button should be visible when the Assigned to field is same as Logged in User and stage is Waiting for Approval.



So your requirement will always contradict. Please review your requirement once.



Regards,


Shloke


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

Regards,
Shloke

Hi Shloke,


If RITM is in waiting_for_approval condition, then i need to hide buttons, irrespective of it is assigned to logged in user or not.


If RITM is in any other stage, other then waiting for approval, then it need to check for logged in user or not.



So am writing the below code.


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


var answer;


if(parent.stage=='waiting_for_approval'){


answer=true;


}


else if((parent.assigned_to!=gs.getUserID()) && (!parent.active))


{


  answer=true;


  }


else{


answer=false;


}