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
Luke@TWSLuke@TWS 

Custom button using Street merg field

Ive been developing a custom button using javascript, I'd like to pull out the address but using {!Lead.Street} for example, when the street is more than one line, will break the javasacript. Is there any easy way around this? I could go down the route of using API calls but I'd like to avoid it if possible.
TCAdminTCAdmin
Hello Luke@TWS,

The only way I have been able to guaranty that the code works is to utilize a retrieve to get the street from the record. Someone else may have a solution but I haven't seen it yet.
Greg HGreg H
Did you try using the SUBSTITUTE() function?  I don't know for sure if that will resolve the problem but may be worth a try.
-greg
Luke@TWSLuke@TWS
Hi Greg,

Thanks for the suggestion but it seems that SUBSTITUTE does not work in this case, ie

Code:
var address = "{!SUBSTITUTE(Lead.Street,'\n','\\n')}";

 will still return something like
var address = \"29 Barton Way \nCroxley Green\"; 

in the final code. SUBSTITUTE will manage to find and replace anything other than '\n'
but that's what's causing the problem so I'm not sure what to try next.