I have a custom button and I am using a modal to prompt the user for input. There is a button that opens a new window url. The variable for the url is not formatting correctly.

custom button javascript:


function insertScript(a) {
    var body = '<h1>Select Office Name</h1>: ';
    var list = sforce.apex.execute("DQCustomButtonUtils", "getProviderFacilities", {
        id: "{!Contact.Id}"
    var offices = JSON.parse(list);
    var box = new SimpleDialog("hersh" + Math.random(), true);
    parent.box = box;
    box.setTitle("Please Select Service Office");
    body += '<select>';
    for (var office in offices) {
        body += '<option value="' + offices[office].ww_Entity_Guid__c + '">' + offices[office].Name + '</option>' + '<br>';
    body += '</select><br>';
    body += "<button class='btn' onclick='window.parent.box.hide(); return false;'>Cancel</button>";
    body += "&nbsp;";
    body += '<button class="btn" onclick="window.open("' + a + '"); return false;">OK</button>';
var a = sforce.apex.execute('DQCustomButtonUtils', 'getProviderWindwardUrl', {
    id: '{!Contact.Id}'

Alert showing variable a's url. This is correctly formatted:

enter image description here

How the button is actually written to the screen

<button class="btn" onclick="window.open(" http:="" localhost:53700="" provider.aspx?id="053659cc-cdde-45d6-826e-95cb787c005e&amp;effdte=2003%2f10%2f01&amp;termdte=12%2f31%2f9999&quot;);" return="" false;"="">OK</button>

I think the slashes ("/") in the "a" variable must be escaped. If you look at the way the button is being rendered, you'll see that where a slash is found the string "breaks up".


I have written a simple solution for rich modals on standard page layouts which would simplify your code here http://www.codebycody.com/2016/11/custom-html-dialog-box-on-standard-salesforce-page-layouts.html

  • If your link actually answers the question, please include the relevant content here. Link-only answers tend to break over time, rendering them less useful. – Adrian Larson Nov 10 '16 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.