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 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.


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
alert("There is a current job on the system - please complete this job prior to creating a new job");

Tags: , , , ,
Posted in S-Controls,, Web Development | Comments Off on JavaScript to Override Buttons

Default values and tracking on Web to Lead forms

Written by ShamrockCRM on July 18, 2009 – 8:36 pm

If you have ever wanted to set default values for certain fields when someone is filling out a Web2Lead form on your website, you absolutely can.  For example, let’s imagine that you have 5 product pages on your website and you have a contact form on each page.  You could set a field called “Originating Web Form” to the value Product 1 or Product XYZ as seen below.  The user filling out this form would never see this field that is filled out behind the scenes, because it is a hidden field.

This allows you to set fields in Salesforce that might trigger different types of workflow rules or could be used for specific marketing tracking.  This is a great, easy way to prefill in data or track certain behavior.

The line below allows you to specify a hidden value that the user does not see.  This will default a field in called “Originating Web Form” with the value “Product XYZ Page.”  This will let you know that the user filled in the form on this specific product page. development web 2 lead

Tags: , , , , , ,
Posted in, Web Development | 2 Comments »