-1

Is there a problem with my javascript on a custom button? Before it was set to URL with the URL variable filled in, but now i want to add logic to this.

Thanks

{!REQUIRESCRIPT("/soap/ajax/21.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")} 

var url = '/apex/QuoteRequestDetailsPage?QuoteRequestId={!Quote_Request__c.Id}
&OpportunitySegmentId={!Quote_Request__c.Opportunity_SegmentId__c}';

window.open(url,"_self");
1
  • If there really is a line break before &OpportunitySegmentId that is a problem.
    – Keith C
    Commented Sep 16, 2016 at 16:36

1 Answer 1

3

You can't use a literal newline in a JavaScript string. This causes an "unterminated string" parsing error.

To fix it, use string concatenation:

var url = '/apex/QuoteRequestDetailsPage?'+
          'QuoteRequestId={!JSENCODE(Quote_Request__c.Id)}'+
          '&OpportunitySegmentId={!JSENCODE(Quote_Request__c.Opportunity_SegmentId__c)}';

Personally, I'd recommend using URLFOR:

var myUrl = "{!URLFOR($Page.QuoteRequestDetailsPage, null,
             [QuoteRequestId=Quote_Request__c.Id,
              OpportunitySegmentId=Quote_Request__c.Opportunity_SegmentId__c])}";
window.open(myUrl, "_self");

URLFOR will take care of all the pesky details of encoding, line breaks, and so on.

Not the answer you're looking for? Browse other questions tagged .