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 »

Free Advanced Search Code

Written by ShamrockCRM on March 4, 2009 – 9:41 pm

Ok, I have decided to be kind.  Everyone saw the post about the Advanced Search tool for already and loved it.  Everyone requested it and I am in a very giving mood.

This is such a great little tool.  You can’t miss out on this little bit of functionality.

This code is incredibly simple and very easy to install.  This can be used on any edition of Salesforce, including Group, Professional, Enterprise and Unlimited.

1) All you need to do is create a Salesforce Home Page Component.

2) Make this component of type “HTML Area.”

3) Click the checkbox that says “Show HTML.”

4) Add this snippet of HTML into the box:

<script language="JavaScript" type="text/javascript">
    function submitSearchForm(){
        var searchField = document.getElementById('advsearchfield');
        document.advsrch.action = '/search/SearchResults?searchType=2&sen=0&setLast=1&str=' + searchField.value;
        return true;
<form name="advsrch" method="post" onsubmit="return submitSearchForm();"><input class="searchTextBox" id="advsearchfield" maxlength="80" size="18" name="sbstr"> <input class="btn" value=" Go! " type="submit"></form>

5) Add this Home Page Component to your Home Page Layout.

6) Done

Wasn’t that easy?  This will now allow you to have one simple search box, remove the old complicated one and search through all custom fields.  (external identifiers are excellent!)

Let me know if you need help installing this!

***Updated 4/1/2009 – Thanks Mike for the Small Improvement to the Code!
***Updated 4/9/2010 – Glenn provided a nifty way to prevent the search box from stealing cursor focus here. He suggests to show an image of a search box and replacing the image on mouseover with the actual search box. You need to take the image from his link above and use the following code below:

  onmousemove="if(getElementById('textBoxImage')) {document.getElementById('textBoxDiv').innerHTML='<input id=\'searchField\' maxlength=\'80\' name=\'sbstr\' size=\'18\' value=\'\' type=\'text\'><input value=\' Go! \' class=\'btn\' type=\'submit\'>'}">
  <div id="textBoxDiv">
    <img id="textBoxImage" src="/resource/1269872073000/TextBoxImage2">

If you are having problems with the Javascript version, use the below plain HTML version

<form action="/search/SearchResults?searchType=2&sen=0&setLast=1" method="post" name="advsrch"><input class="searchTextBox" maxlength="80" name="sbstr" size="18" value="" type="text"> <input value=" Go! " class="btn" type="submit"></form>

Tags: , , , , , , ,
Posted in Business Analysis, S-Controls, | 42 Comments »

Modifying Dates Using Javascript

Written by ShamrockCRM on January 27, 2009 – 9:57 pm

CAUTION:  Technical jargon!!! Non-Business Related!!! Only interesting for Salesforce Developers.  :)

I ran across this interesting little problem while creating an orchestration in Cast Iron. I was creating a custom function that would adjust dates forward and back by weeks at a time.

What I found was, my small piece of code worked flawlessly 75% of the time. The 25% of the time would return a calculated date, or error, of “NaN-NaN-NaN.” I could not figure out what was wrong. I tested the code in the browser and everything worked properly.

From further testing and analysis, I determined that the code only broke when the month was July, August, and September or the day was the 7th, 8th, or 9th. I thought that this was very odd.

The code was taking a standard Salesforce date string formatted like “YYYY-MM-DD”, parsing out the text for the year/month/day, and using the parseInt Javascript function to convert the year/month/day into numeric values. I then created a Date object in Javascript and then made the date modifications.

Well, it turns out that parseInt is a bit quirky. If you do parseInt(“06”), this will return the number 6. If you do parseInt(“09”), this will return 0. ZERO?!?! Yes, 0. This is because parseInt will expect the number to be in Octal format if there is a 0 in front. There is no 09 in Octal. This causes the code to return 0, instead of the expected 9. So, when I subtracted 1 from the month to put the month in proper Javascript Date format, my code was inserting -1 as the month, therefore creating an invalid date. This only happened for the 7th, 8th and 9th months.

To resolve this, it was very simple. All you need to do is add “, 10” after the number to parse into an Integer (declaring a Radix) and it will consider this number to be of Base 10, solving your issue.  So, the correct code would be parseInt(“09”, 10).

To learn more about Javascript date modification for S-Controls, take a look at this W3 Schools link.

Tags: , , , , ,
Posted in Programming, S-Controls,, Web Development | Comments Off on Modifying Dates Using Javascript