Salesforce.com JavaScript to Override Buttons
Written by ShamrockCRM on July 23, 2009 – 7:20 pm -This little snippet of code is written in JavaScript. This piece of code is simply an example of what you can do by embedding JavaScript into a custom Salesforce.com button.
In this example, we have Opportunities and a related custom object called Shipments. You sell a Product and you ship it, get it?
This button would be displayed on the “Shipments” related list on an Opportunity. The button would be titled “New Shipment” and would replace the default button.
This button would check if a shipment for this Opportunity is currently “In Progress” and not “Shipped”. If so, it will not allow the user to create a new shipment. They should combine this new shipment into the existing one to save on transportation costs.
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
var result = sforce.connection.query("Select Id From Shipment__c where Status__c = 'In Progress' and Opportunity__c = '{!Opportunity.Id}' ");
var records = result.getArray("records");
//If there are no Shipments In Progress, redirect the User to the New Shipment page
if (records.length == 0){
window.parent.location.href="{! urlFor( $Action.Shipment__c.New, $ObjectType.Job__c,null,true)}&CF00N20000001B5jC_lkid={!Opportunity.Id}&CF00N20000001B5jC={!Opportunity.Name}";
}
//If there are Shipments In Progress for this Opportunity
else{
alert("There is a current job on the system - please complete this job prior to creating a new job");
}
Related posts:
- Modifying Salesforce.com Dates Using Javascript
- Sidebar Javascript Manipulation of Edit Pages
- New Salesforce.com Advanced Search Tool
- About Salesforce.com
- Automatically Refreshing Dashboards
Tags: buttons, code, development, javascript, S-Controls
Posted in S-Controls, Salesforce.com, Web Development | No Comments »
Posted in S-Controls, Salesforce.com, Web Development | No Comments »
