Execute Javascript from Formula field
March 6, 2015
Yes, formula fields can be used to execute javascript code on click. For this, we make use of the HYPERLINK Function.
The syntax for it is:
HYPERLINK("javascript:<your javascript code>","TEXT")
Examples:
To reload the page:
HYPERLINK("javascript:window.location.reload()","TEXT")
To open a SubTab:
HYPERLINK("javascript:srcUp('URL')","TEXT")
HYPERLINK("javascript:sforce.console.getEnclosingPrimaryTabId(function(result){sforce.console.openSubtab(result.id, '', true, '' , null);})") [DEPRECATED FOR USE IN STANDARD SERVICE CONSOLE - USE SRCUP INSTEAD]
Go ahead and knock yourself out!