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
KerryGroup DevKerryGroup Dev 

URL encoding merge fields in S-Controls

I have a rather sticky problem with double quotes and opportunity names.

 

When a person uses a double quote, logic in a custom S-Control does not work because there is string concatenation within some java script.

 

This happens because the java script contains merge fields where are essentially plugged into the java script before that java script is sent to the client browser.

 

parent.frames.location.replace(“http://www.somenewsite.com?oppname= “ + escape(“{!Opportunity_Name}”));

 

 

If the opportunity name happens to include a double quote this function will not work. Any other invalid character will be replaced by the java script ‘escape’ function. To see why this happens look at the two following examples.

 

EXAMPLE 1

Opportunity name: Opportunity1

 

Resulting Java script after merge field applied by SFDC.

 

parent.frames.location.replace(“http://www.somenewsite.com?oppname= “ + escape(“Opportunity1”));

 

 

EXAMPLE 2

Opportunity name: Opportunity “2”

 

Resulting Java script after merge field applied by SFDC.

 

parent.frames.location.replace(“http://www.somenewsite.com?oppname= “ + escape(“Opportunity “2””));

 

 

As you can see the second example contains invalid java script syntax and will cause an error.

 

How can I encode the result coming from the SFDC merge field?

 

 

Currently I use a validation rule on the opportunity:

 

OR(CONTAINS( Name , "\""),CONTAINS( Name , "'"))

 

But I would rather allow double quotes

 

Any ideas?

sfdcfoxsfdcfox
That's a sticky situation, of course. Probably you'll want to run a retrieve() call if you can, do avoid that condition. If that's not possible, then maybe consider a formula field that uses SUBSTITUTE on the opportunity name to "escape" the quotes on the Salesforce side before they get merged in to the S-Control...

~ sfdcfox ~
lee.boonstralee.boonstra
http://community.salesforce.com/sforce/board/message?board.id=general_development&message.id=1285