function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
n_pavan_kumar1n_pavan_kumar1 

To remove "Submit for Approval" button from the Approval History related list once case is approved

Hi,

 

Here is a requirement to remove the button "Submit for Approval" from the Approval History related history list from a case page layout once the case is approved.

 

I didnt find any settings to remove  the button in the page layout properties.

 

Please share your ideas if  you had come across this requirement with any workarounds.

 

Thanks in advance,

Pavan

 

Best Answer chosen by Admin (Salesforce Developers) 
agum34agum34

I was able to use a sidebar component and jQuery to remove the Submit for Approval button.  We needed some custom logic to execute before the record entered the approval process so we added a custom button to submit for approval and removed the submit for approval button on the Approval History section by adding the following sidebar component.  Note this will break if Salesforce changes the name of the button component "piSubmit".  Replace the ###### with a reference to a static resource with the jQuery.js.  You can't use the functions in sidebar components for URLFOR.

 

<script src="/resource/#############/jQuery"></script>
<script>
  $j = jQuery.noConflict();

  // Added a check for a specific custom object
  if(window.location.href.indexOf(".com/a14") != -1) {
    $j(document).ready(function() {     
      $j("input[name='piSubmit']").hide();
    });
  }
</script>

 

All Answers

goabhigogoabhigo

Not a proper solution but try it.

 

Remove Submit for Approval button from the related list. I hope in the detail page you have that button. Now create 2 record types - one including that button, another without button. When the approval status(picklist, usually) changes to Approved, change the record type to 2nd type(with the help of workflow).

 

Done.

n_pavan_kumar1n_pavan_kumar1

Hi Abhi,

 

Thanks for the reply, that works for the main case page layout. But it doesnot work for the related history page layout "Approval History". Even if i edit this page layout, i willnot get an option to edit/ remove the Button properties for this related list page layout.

 

Thanks,

Pavan

goabhigogoabhigo

Ohh yeah, you cannot remove it.

 

The only solution I can give you for time being is to update the approval entry criteria so that it fires only if the status is not approved ;)

agum34agum34

I was able to use a sidebar component and jQuery to remove the Submit for Approval button.  We needed some custom logic to execute before the record entered the approval process so we added a custom button to submit for approval and removed the submit for approval button on the Approval History section by adding the following sidebar component.  Note this will break if Salesforce changes the name of the button component "piSubmit".  Replace the ###### with a reference to a static resource with the jQuery.js.  You can't use the functions in sidebar components for URLFOR.

 

<script src="/resource/#############/jQuery"></script>
<script>
  $j = jQuery.noConflict();

  // Added a check for a specific custom object
  if(window.location.href.indexOf(".com/a14") != -1) {
    $j(document).ready(function() {     
      $j("input[name='piSubmit']").hide();
    });
  }
</script>

 

This was selected as the best answer
Koushik.ax1218Koushik.ax1218

Hi

 

could you please share the complete code...

 

Thanks

koushik

agum34agum34

Besides a copy of jQuery (or you can link to it see http://docs.jquery.com/Downloading_jQuery) that is really all the code you need.  Add that script to any sidebar component and make sure the "Show Custom Sidebar Components on All Pages" in User Interface settings is enabled.  The code will look for the Submit for Approval button on page load and hide it from the user.  Let me know if you have any more questions on setting it up.  

 

FYI - I used the prefix of the object to selectively remove the button.  In our case not all submit for approval buttons needed overriding so this will only hide the button on the object with the prefix 'a14' which is a custom object in our Org.


Thanks,

Alex

Koushik.ax1218Koushik.ax1218

Hi

 

I tried with jquery. But it did not work.

 

<script src="/resource/Jquery_1_8_11/jQuery"></script>
<script>
  $j = jQuery.noConflict();

  // Added a check for a specific custom object
  if(window.location.href.indexOf(".com/a14") != -1) {
    $j(document).ready(function() {    
      $j("input[name='piSubmit']").hide();
    });
  }
</script>

 

 

src="/resource/Jquery_1_8_11/jQuery is static library in my org. It did not work.

 

 

Thanks

koushik

agum34agum34
<apex:page >
 
{!URLFOR($Resource.Jquery_1_8_11)}

</apex:page>

Because sidebar components do not support Visualforce expression language you have to get a URL for the static reference to use in your html.  I use the sample visualforce page above to get the URL for a static reference.  It should look something like  /resource/1310072847010/Jquery_1_8_11.  Then use the following snippet for your custom object (a3k) replacing the ######### with the number you found using the sample VF page above.  


<script src="/resource/##########/Jquery_1_8_11/jQuery"></script>
<script>
$j = jQuery.noConflict();

  //Added a check for a specific custom object
  if(window.location.href.indexOf(".com/a3k") != -1) {
    $j(document).ready(function() {    
      $j("input[name='piSubmit']").hide();
    });
  }
</script>

 Note that uploading new versions of the static resource will change this number and you have to rerun the sample VF page and update your sidebar component.  I have not found a way to get the static resource using just html (no VF) but I am sure there is a solution out there if someone wants to share it.

 

Alex


DodgyDodgy

Hi, Alex!  Thanks for taking the time to write this up--we're in exactly the same situation, and we have successfully added a custom approval button.  I've been unable to get the standard button to hide, however.  I'm hoping you or someone might still be looking at this thread and be able to give me suggestions.  I don't have any previous experience using jQuery, so that might be where I'm going wrong.

 

I downloaded a file named 'jquery-1.7.2.min.js' and uploaded it as a static resource called 'jQuery'.  I used your Apex cheat to find the URL for this resource, and updated your script to point to that new URL and changed the object prefix to match our object.  I can see the component listed in the sidebar, but the standard approval button still appears.  Any suggestions?  Many thanks in advance!

 

<script src="/resource/1334848077000/jQuery"></script>
<script>
  $j = jQuery.noConflict();

  // Added a check for a specific custom object
  if(window.location.href.indexOf(".com/a0R") != -1) {
    $j(document).ready(function() {     
      $j("input[name='piSubmit']").hide();
    });
  }
</script>

 

DodgyDodgy

Never mind!  I found that with two changes I was able to get this to work:

  1. The commented line seemed to be causing an issue (I found a reference to it on tehnerd's post here: http://www.tehnrd.com/show-and-hide-buttons-on-page-layouts/).
  2. "Enable Separate Loading of Related Lists" under the User Interface settings needs to be turned off.

Making those two changes got this to work!  Thanks again for posting the details, Alex!  Now I need to determine what kind of performance impact changing the Separate Loading of Related Lists wil have...

Sanchivan SivadasanSanchivan Sivadasan

Hi Alex,

 

Can you guide me on how to add this custom component? I am trying to do something very simliar and can't seem to add the custom component to the side bar. Can you show me the steps to archieve this? thank you very much.

 

FG

agum34agum34
I added the code to an existing home page component (Setup-Customize-Home-Home Page Components) but if you add a new one just make sure it is an HTML area and check the Show HTML box in top right of the editor. Then you can add in the jQuery code in my earlier post. Make sure to use the test visualforce page to get the static resource reference for jQuery (13 digit number) since you cannot use URLFOR in Home Page Components. Also make sure you add the component to your sidebar and that you have the sidebar enabled. Good luck!
SoleesSolees

Thanks this worked as a charm !!

 

Swayam5745Swayam5745

Hi Alex,

 

Below is the code I have used.

 

 

<script src="/resource/1372759842000/Hide_Submit_For_Approval_Button_Js/jQuery"></script>        
<script>		
    $j = jQuery.noConflict();        
    if(window.location.href.indexOf(".com/Cos") != -1) {
        $j(document).ready(function(){$j("input[name='piSubmit']").hide();});                
    }
</script>

 

My static resource name is 'Hide_Submit_For_Approval_Button_Js'.

 

I am still not able to hide the button.

DancyDancy
Thank you so much Alex... Ur explanation helped me a lot.
Tons of thanks once again...
Chait_SFDCChait_SFDC
Hello Everyone,

This is such a wonderful post and I just love this information. We have a requirement to hide "Recall Approval Request" button. This button only appears to our system admins after a record being submitted for approval and if the record is waiting for approval. I am assuming that the same process will work here and I just need to know the button name that I can use in the script. I tried with piRecall / recall but it is of no luck. Appreciate all your assistance.
cmsweetcmsweet
@Chait_SFDC - the element Id is 'piRemove', you'll also want to make sure you update the window.location line to match the object you want this to affect.

With the coming SFDC changes, we'll no longer be able to use quick JS hacks like this to solve our little UI issues. HTML will only allow you to use the WYSIWYG editor. Future JS will have to be added as a VF page, which isn't absolutely terrible, except for the cross-domain problem. We're currently investigating that to see if there is any workaround as we really need the ability for navbar JS to add/remove/alter standard UI without having to create new VF pages for every standard layout.
Anton YoganathanAnton Yoganathan
Hi friends,
I have a different approach for this issue.
If you want to replace the Submit for approval button in the detail page .
do the following.

Replace the detail page with a vf page as follows.

<apex:page standardController="Object__c" tabStyle="Object__c">
<apex:form id="myForm">
    <apex:pagemessages />
    <apex:detail subject="{!Object.Id}" relatedList="true" inlineEdit="false" />       
</apex:form>
</apex:page>

And in this page add the following script

<script language="JavaScript" type="text/javascript">
 
  
    var allTdTags = document.getElementsByTagName('td');
    for(var i=0;i<allTdTags.length;i++){
       
     if(allTdTags[i].className == 'pbButton'){
                     document.getElementsByName('piSubmit')[0].style.display = "none";          
        }
    }
</script>

 so the final out put code would look like this....



<apex:page standardController="Object__c" tabStyle="Object__c">
<apex:form id="myForm">
    <apex:pagemessages />
    <apex:detail subject="{!Object.Id}" relatedList="true" inlineEdit="false" />      
</apex:form>
<script language="JavaScript" type="text/javascript">

 
    var allTdTags = document.getElementsByTagName('td');
    for(var i=0;i<allTdTags.length;i++){
      
     if(allTdTags[i].className == 'pbButton'){
                     document.getElementsByName('piSubmit')[0].style.display = "none";         
        }
    }
</script>

</apex:page>



This code works fine. This code removes the Submit for approval button form the Details page.
Now you can create your owm custom button replacing this button.



subrat_raysubrat_ray
Hi Alex,
Below is my code on a side bar (home page VF Area component).

<apex:page >
  <script src="/resource/1423827610000/jQuery"></script>

  <script>
  $j = jQuery.noConflict();
  if(window.location.href.indexOf(".com/001") != -1) {
     $j(document).ready(function() {    
        $j("input[name='piSubmit']").hide();
     });
  }
</script>
</apex:page>

But, Submit button still appears on account page. Any mistake I am doing here?

Appreciate any response.