You need to sign in to do that
Don't have an account?
Shamus Kelley 4
Incremental counter each time a custom button is clicked
I'm looking to track/count each time a custom button is clicked. i.e. each time Send Quote is clicked, i'd like to see the count go up incrementally. *This custom button is an onclick javascript. Thank you in advance.
You can try the following. From the code you posted it seems like you have this button from the Opportunity object and not the Quote object. Please note that you will have to replace Click_Counter__c with the custom field you created to store the click counts.
All Answers
try{
// check that Opp has the necessary approvals in order to continue
var strCheck = "{!Opportunity.Approval_Required__c}".toLowerCase();
if ( strCheck.indexOf("quote") == -1) {
try{
var result = sforce.apex.execute(
'Opportunity_Buttons', // class name
'createQuote', // method name
{ // arguments
oppIDraw:"{!Opportunity.Id}",
generateQuoteNum:"true"
}
);
if (result[0].success == 'true') {
//window.location = result[0].msg;
window.open(result[0].msg, "quoteWin");
} else alert(result[0].msg);
}
catch(ex){
alert("Error: "+ex);
}
} else alert("No Quote can be generated because Approvals are required");
}
catch (ex) {
alert("Error: " + ex);
}
You can try the following. From the code you posted it seems like you have this button from the Opportunity object and not the Quote object. Please note that you will have to replace Click_Counter__c with the custom field you created to store the click counts.
try{
var clickCntStr = '{!Opportunity__c.Count__c}';
var oppname = '{!Opportunity__c.Name}';
clickCntStr = clickCntStr == null || clickCntStr == "" ? "0" : clickCntStr;
clickCnt = parseFloat(clickCntStr);
++clickCnt;
var updOpp = new sforce.SObject("Opportunity__c");
updOpp.Id = '{!Opportunity__c.Id}';
updOpp.Count__c = clickCnt;
var result = sforce.connection.update([updOpp]);
location.reload(true);
}
catch(ccex){
console.log('click count increment error: ' + ccex);
}
This is fine but also I have a standard name field as sson as button has been clicked
Name should increment in the below way: 1 , 2 , 3, 4 are the Count__c in the above mentioned script
AHG/OPP/2018/1
AHG/OPP/2018/2
AHG/OPP/2018/3
AHG/OPP/2018/4
...................
I'm circling back to this request as i'm having trouble implementing the code. I've tried both suggestions thus far but without 100% success. I get the following error message: "Error: TypeError: Cannot read property 'execute' of undefined"
This is the script I'm working with so far:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
try{
var clickCntStr = '{!Opportunity.Quote_Generated_Count__c}';
var oppname = '{!Opportunity.Name}';
clickCntStr = clickCntStr == null || clickCntStr == "" ? "0" : clickCntStr;
clickCnt = parseFloat(clickCntStr);
++clickCnt;
var updOpp = new sforce.SObject("Opportunity");
updOpp.Id = '{!Opportunity.Id}';
updOpp.Quote_Generated_Count__c = clickCnt;
var result = sforce.connection.update([updOpp]);
location.reload(true);
}
catch(ccex){
console.log('click count increment error: ' + ccex);
}
try{
// check that Opp has the necessary approvals in order to continue
var strCheck = "{!Opportunity.Approval_Required__c}".toLowerCase();
if ( strCheck.indexOf("quote") == -1) {
try{
var result = sforce.apex.execute(
'Opportunity_Buttons', // class name
'createQuote', // method name
{ // arguments
oppIDraw:"{!Opportunity.Id}",
generateQuoteNum:"true"
}
);
if (result[0].success == 'true') {
//window.location = result[0].msg;
window.open(result[0].msg, "quoteWin");
} else alert(result[0].msg);
}
catch(ex){
alert("Error: "+ex);
}
} else alert("No Quote can be generated because Approvals are required");
}
catch (ex) {
alert("Error: " + ex);
}
Any help on resolving is greatly appreciated!