+ Start a Discussion
Felicia Abramson - Bit9Felicia Abramson - Bit9 

Display Buttons based on Field

We have some custom buttons being developed that we only want to be displayed if items in a picklist match a certain criteria. For example, if the product field is a product that starts with the letter A, don't show the the buttons. If the product selected starts with the letter B, show the buttons (we only have two options that products can start with so it's pretty simple).

My initial idea was to use record types, page layouts, and WFR's, but we already use record types and there is potentially alot of intergration from our software engineers who use this object that we don't want to worry about messing that up. So while we work that part out, is there anything programatically we can do to show or hide buttons based on a field on the record? Without using record types?
Balaji Chowdary GarapatiBalaji Chowdary Garapati

@Felicia Abramson - Bit9:

  we can use formula fields for this purpose. For eg., the below formula will display a button image which on-cllck redirects to the desired page.
IF( BEGINS(text(PRODUCT), 'A'),'' HYPERLINK("place your desired page url here", IMAGE("put the url for the image","put some meaning ful text here that wil  be display when hover over of that image"),NULL)

Note: your desired image url can be screen shot of a button which is in the static resources for eg., create a  custom  button and add it to page layout, take a screeshot of just the button and add it in static resources. it can be accessed via url '/resource/nameofstaticresource'



These can be added to the page layout as a field and can not be on top of page as we see "EDIT","Delete" buttons on top. 
Now if the condition doesnt meet, the button will not be displayed on the page how ever the label for the button exisits as it is nothing but a field.

Hope this helps

Thanks,
balaji
Felicia Abramson - Bit9Felicia Abramson - Bit9
Thanks Balaji. Sent this to the guy developing the button to see if it's something he tried, I'll let you know if it works for us.
Anil SavaliyaAnil Savaliya
Hey Felicia,

Write JavaScript just like example in below link and add in static resouse and flow step.

http://www.tehnrd.com/show-and-hide-buttons-on-page-layouts/


Steps :

1. create a StaticResouce "YourStaticResourceName" upload a JS file containing whatever you need (e.g. jquery) and add a command in the end, like 2. console.log('bingo!');
2. go to Setup > Home > Custom Links
3. create a new link call it "injection"
4. Behaviour = "Execute JavaScript"
5. Content Source = "Onclick JavaScript" (don't get irritated, you won't have to click!)
at the body enter {!REQUIRESCRIPT("/resource/1402932484000/YourStaticResourceName")}
6. go to Setup > Home > Home Page Components
7. create a new one
8. call it "injection-box"
9. pick type "Links" (instead of HTML-Area we used before)
10. click next
11. pick "injection" we created above
12. save it
13. got to Setup > Home > Home Page Layouts
14. add "injection-box" to your layout
go to anywhere it worked before and check for 'bingo!' in your console. See that 'YourStaticResourceName' is successfully injected to the standard pages :-)
And finally it seems to be even officially supported, look at this:
http://help.salesforce.com/HTViewHelpDoc?id=customize_functions_i_z.htm#REQUIRESCRIPT
Felicia Abramson - Bit9Felicia Abramson - Bit9
Thanks Anil. Sent that off to our development guy as well.