+ Start a Discussion
Shamus Kelley 4Shamus Kelley 4 

Update OnClick java script to populate a number filed (i.e. counter) to show how many times the button is pushed?

Hello - 

I need to update the javascript within this button so that a custom field (i.e. counter__c) is updated every time the button is clicked. Any help is greatly appreciated! 

Here is the current OnClick Java Script that needs modification:

// check that Opp has the necessary approvals in order to continue 
var strCheck = "{!Opportunity.Approval_Required__c}".toLowerCase(); 
if ( strCheck.indexOf("quote") == -1) { 
var result = sforce.apex.execute( 
'Opportunity_Buttons', // class name 
'createQuote', // method name 
{ // arguments 


if (result[0].success == 'true') { 
//window.location = result[0].msg; 
window.open(result[0].msg, "quoteWin"); 
} else alert(result[0].msg); 

alert("Error: "+ex); 

} else alert("No Quote can be generated because Approvals are required"); 

catch (ex) { 
alert("Error: " + ex); 
Dushyant SonwarDushyant Sonwar
Hi Shamus,

You can create a checkbox field for this  onm Opportunity default will be false, when button is clicked checks it's value to true. So that way you don't need to maintain counter for button.

Hope this helps.
Dushyant SonwarDushyant Sonwar

You can also disable your custom button  and reenable it after the process completes on standard detail page , so that no one  will able to click multiple times.  You need to find the element id by using inspect element of browser using right click . Below link will give you an idea about disabling the button on standard layout.

Hope this helps.
Shamus Kelley 4Shamus Kelley 4
@Dushyant Sonwar - Thank you for the reply! With your first suggestion, how do you envision the checkbox going from False to True? Would this be done with a process or wf field update? 
Dushyant SonwarDushyant Sonwar


Actually i was saying that  you can update a custom boolean field to true on custom  javacript button , during this process disable the button so that way your field will update the value to true and user won't be able to click multiple times during that process , when process of updation completes , you can undisable the button.


Shamus Kelley 4Shamus Kelley 4
@Dushyant Sonwar - The reason I'd like a number field is so that each time the button is pushed, I can keep track on the number of quotes incrementally generated. as of now, these quotes are created as a PDF file attachment. Not something I can report on. Are you able to help with the line/script that needs to be added to the java within this button to satisfy that?