jeromenirmal
7/24/2013 - 1:55 AM

JavaScript Samples

JavaScript Samples

/**
* SUBMIT APPROVAL VIA A BUTTON
* http://nefdev.wordpress.com/2012/06/22/submitting-for-approval-using-a-javascript-button-and-ajax/
**/
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}

var confirmed=confirm(“{!$Label.Submit_For_Approval_Confirmation_Dialog}”);

if (confirmed==true)
{
sforce.apex.execute(“OpportunityWebService”,”setManagerAndRegionalDirector”,{sOpportunityId:”{!Opportunity.Id}”});

var approval = new sforce.ProcessSubmitRequest();
approval.objectId = “{!Opportunity.Id}”;
var processRes = sforce.connection.process([approval]);

window.location=(“/{!Opportunity.Id}”);
}
{!REQUIRESCRIPT("soap/ajax/28.0/connection.js")} 
{!REQUIRESCRIPT("soap/ajax/28.0/apex.js")} 

var approvedMsg = ""; 
var errorMsg= ""; 
var apprBy= ""; 

if("{!Quote.CCA_Required__c}" == 0 && "{!Quote.SMA_Required__c}" == 0 && "{!Quote.SPA_Required__c}" == 0){ 
approvedMsg = "This quote does not require approvals. Please proceed to submit by clicking \'View POP Quote'\ button."; 
}else if("{!Quote.Status}" == 'Approved' || "{!Quote.Status}" == 'Received'){ 
approvedMsg = "This quote has been approved."; 
}else if("{!Quote.Status}" == 'Pending Approval'){ 
approvedMsg = "This quote has been submitted for approval."; 
} 

errorMsg += ("{! Quote.Key_Reason__c }")? "" : "Key Reason"; 
errorMsg += ("{!JSENCODE(Quote.Special_Pricing_Request_Detail__c)}")? "" : "\nSpecial Pricing Request Detail"; 
errorMsg += ("{! Quote.Key_Competitor__c }")? "": "\nKey Competitor"; 

apprBy = ("{!Quote.CCA_Required__c}")? "Comm Consultant and Sales Manager" : ""; 
apprBy += (!"{!Quote.CCA_Required__c}" && "{!Quote.SMA_Required__c}")? "Sales Manager" : ""; 
apprBy += ({!Quote.SPA_Required__c})?" and Pricing Approval":""; 


if(approvedMsg){ 
alert("\n\NOTIFICATION\n--------------------\n\n" + approvedMsg); 
} 
else if(errorMsg){ 
alert("\n\NOTIFICATION\n--------------------\n\nPlease fill-in Pricing Request Information. Following details are missing : \n\n" + errorMsg ); 
} 
else if(Modal.confirm && Modal.confirm('\n\NOTIFICATION\n--------------------\n\nPOP Quote will be locked during approval process. \n\nDo you want to continue?\n')) 
navigateToUrl('/p/process/Submit?id={!Quote.Id}&retURL=%2F{!Quote.Id}');