3

With Summer 15 release coming up quickly, and the HTML markup area going away on home page components, I wanted to pose this question. I have some code markup that makes it so that a button disappears on the quote page once the submit for approval button is clicked by the user. I asked Salesforce Support if this could be accomplished any other way, and they said that it could not. I find that hard to believe and was wondering if anyone had any ideas on how I could accomplish this. Currently I have this code in an HTML area home page component:

<!-- We can locate this div with the script below, traverse up the DOM and then hide the entire sidebar component. -->
<div id="sidebarComponentLocator">If you see this, something is broke with Dynamic Button functionality.</div>
<!-- Import jQuery from google CDN, could also be static resource-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
/*Immediately create a unique alias for this version of jQuery to prevent conflicts with other js libraries*/
var j$ = jQuery.noConflict();
/*Determine what type of object is currently being displayed on the page. Only confident way to do this is get object prefix */
var objectPefix = window.location.href.substring( window.location.href.indexOf('.com/') + 5, window.location.href.indexOf('.com/') + 8 );
/*Query the records from Dynamic_Button__c object as soon as possible, don't wait for DOM ready event*/
var result = sforce.connection.query("Select Button_Name__c, Field_Id__c, Field_Value__c from Dynamic_Button__c where Object_Prefix__c = '" + objectPefix + "'");
var records = result.getArray("records");
/*Execute this code block once page DOM has fully loaded*/
j$(document).ready(function(){
    /*Hide the sidebar last as this is lowest priority. First priority is show/hiding the buttons. 
        Find the sidebarComponentLocator, then find parent div with class 'sidebarModule' and the hide it*/
    j$("#sidebarComponentLocator").closest(".sidebarModule").hide().prev().hide();
    /*First loop through the dynamic button records and hide any that are on the layout. We must first hide all the buttons
        as the Dynamic Button records only contan the 'show' logic*/         
        for (var i = 0; i< records.length; i++) {             
            /*Hide buttons define in Dynamic_Button__c object*/             
            j$("input[name='"+ records[i].Button_Name__c.toLowerCase() +"']").hide();         
        }                 
        /*Now loop through the Dynamic_Button_Records and show button if field value matches that define in record*/         
        for (var i = 0; i< records.length; i++) {             
            /*Get the value from the field on the page layout*/             
            var recordValue = j$("#"+records[i].Field_Id__c+"_chkbox").attr('title');             
            var showValue = records[i].Field_Value__c;                         
            /*Show the button if the value of the field on this record matchs the setting in the Dyamic_Button__c*/             
            if(recordValue == showValue){                 
                j$("input[name='"+ records[i].Button_Name__c.toLowerCase() +"']").show();             
                }         
        }
}       
</script>

Appreciate any help! Thanks.

  • See End of javascript sidebar workarounds? for a work-around that exploits the ability to execute JavaScript in custom links for now. That ability may also be removed in Winter '16, but at least you would have a few more months to prepare your users for the change. – Keith C May 19 '15 at 21:48
2

I saw this on another Stack.

This can be pulled off, but you need to get crafty :-) here's one I prepared with pink candy polka dots:

enter image description here

  1. go to Setup > Create > Objects > [Your Object] > Custom Buttons and Links, and hit New,
  2. create a Detail Page Button whose behaviour is to Execute JavaScript,

  3. modify the following JavaScript, using your lowercased button name in lieu of your_button:

    (function() {
      var button = document.getElementsByName('your_button')[0];
      button.style.background = 'url("https://addons.mozilla.org/_files/311357/preview_small.jpg")';
    }());
    
  4. use a base64 encoder to format your JavaScript, which we'll load and execute as a Data URI,

  5. paste it into the formula, noting the data:application/javascript;base64, prefix:

    {!REQUIRESCRIPT("data:application/javascript;base64,KGZ1bmN0aW9...wZyIpJzsKfSgpKTs=")}
    window.location = '/apex/ns__PageName'; //button action when clicked
    

The usual caveat applies: using a Data URI here may be subject to future validation, but rest assured for now Salesforce support the use of REQUIRESCRIPT in a Custom Button. Your use is only cosmetic.

Further, if you wanted to separate the button click outcome from the pink candy polka dots, you could put the cosmetic JavaScript in a separate Custom Link which you place somewhere on the page layout. It's one novel way of running JavaScript in the scope of a standard page without needing to configure the sidebar or use a narrow Home Page Component.

Other than this you should probably control this using page layouts, alternatively use some JS code to ensure that when the opp has been submitted for approval that the button can not be clicked.

0

I actually just changed the button from a URL redirect to use onClick JavaScript and made a conditional statement to look at a certain field within the Quote object.

if({!Quote.Submitted_for_Approval__c} != true){
    location.assign("https://cs9.salesforce.com/apex/ServiceRecordLayoutButton?id={!Quote.Opp_Id__c}");
}
else{
    alert("Sorry! You cannot edit products if your quote is submitted for approval. Please Recall the approval request if you need to make changes to your quote line items.");
}

Thanks @Timothy for responding to my post. Your idea probably does work, but seemed a little complicated for me right now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.