function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

OnClick Javascript - Ampersand in Account Problem

I use the following custom button OnClick Javascript code to pass some values and create a new Case from a Contract.

var CaseURL = "/500/e?CF00N70000002BrKD={!Contract.ContractNumber}&CF00N70000002BrKD_lkid={!Contract.Id}&cas4_lkid={!Contract.AccountId}&cas4={!Contract.Account}&cas5=Maintenance%20Request%20RMA&retURL=%2F{!Contract.Id}";

The code does exactly what it's supposed to do but when a value for Account is passed through that has an ampersand in it everything after the ampersand is left off ex. "Jack & Jill" becomes "Jack".  When you save everything it is corrected since the ID was properly assigned but I'd sure like to not have my users alarmed when they see the name botched.

So far I've tried to surround {!Contract.Account} with single (%27) and double quotes (%22) but all that does is put a single or double quote in front of the value.

Thanks much.
You can use the SUBSTITUTE function to replace the ampersands, but I would suggest you use the URLFOR function:

var CaseURL = {!URLFOR($Action.Case.NewCase, $ObjectType.Case, [
  cas5="Maintenance Request RMA",
  retUrl=URLFOR($Action.Contract.View, Contract.Id)])}

Also, I don't think you need to fill the IDs (lkid).

Message Edited by maziz on 11-26-2008 01:55 PM
Thank you very much.  I've been searching high and low looking for references on things like this and everything I find is old.  Any good links on reference for this approach?  I ask about reference as I'm getting the following error when I try to use the code... A problem with the OnClick JavaScript for this button or link was encountered: invalid flag after regular expression.

Oh, you should put the string within quotes or double quotes, as you did in your previous example.
Santosh KumbarSantosh Kumbar

See the changes made in the URL below...It should now pass the AccountID field into Case Account Lookup field



var CaseURL = "/500/e?CF00N70000002BrKD={!Contract.ContractNumbe