0

I'm trying to use JSENCODE to prevent an un-terminated string literal in the following string:

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

var newRecords = [];
var appObj = new sforce.SObject("Application__c");
appObj.Id = "{!JSENCODE(AFC_Contract_Shell__c.ApplicationId__c)}";
appObj.eContract__c = true;
newRecords.push(appObj);

window.location.href = encodeURI('
https://composer.congamerge.com
?sessionId={!JSENCODE(API.Session_ID)}
&serverUrl={!JSENCODE(API.Partner_Server_URL_80)}
&id={!JSENCODE(AFC_Contract_Shell__c.Id)}
&QueryID=[BusinessAccount]a1Qa0000001uKKK,
[PrincipalContact]a1Qa0000001uKKO,
[FloorplanFee]a1Qa0000001uKKR,
[NumberofCurtailments]a1Qa0000001uKKM,
[Interest]a1Qa0000001uKKP,
[CurtailmentFee]a1Qa0000001uKKN,
[Principal]a1Qa0000001uKKH,
[BusType]a1Qa0000001uKKJ,
[DateInWords]a1Qa0000001uKKQ,
[CurtailmentTermWord]a1Qa0000001uKKL,
[PrincipalSum]a1Qa0000001uKKI,
[BusinessName]a1Qa0000001uKKF,
[GuarantorSig]a4G13000000LP1o?pv0={!JSENCODE(AFC_Contract_Shell__c.Id)},
[PrimarySig]a4G13000000LP1y?pv0={!JSENCODE(AFC_Contract_Shell__c.Id)}
&ReportID=[PContacts]00O13000008jhuD?pv0={!JSENCODE(AFC_Contract_Shell__c.ApplicationId__c)}


&LG0=0
&LG1=Contract+Generated
&LG4=1
&SelectTemplates=1
&Templategroup={!JSENCODE(CASE(AFC_Contract_Shell__c.Name,
"US Contract", "USAFCeContracts",
"US Amendment", "USAFCeContracts",
"California Contract", "CALAFCeContracts",
"California Amendment", "CALAFCeContracts",
"Canada Contract", "CANAFCeContracts",
"Canada Amendment", "CANAFCeContracts",
"AFC Credit"))}


&DocuSignVisible=1
&DS7=7
&DocuSignTag=1
&DocuSignEmailSubject={!JSENCODE(AFC_Contract_Shell__c.AFC_Dealer_ID__c)}+Your+AFC+Contract+is+Ready

&QVar0ID=a4G13000000LPCO?pv0={!JSENCODE(AFC_Contract_Shell__c.ApplicationId__c)}
&QVar1ID=a4G13000000LPCP?pv0={!JSENCODE(AFC_Contract_Shell__c.ApplicationId__c)}
&QVar2ID=a4G13000000LPCQ?pv0={!JSENCODE(AFC_Contract_Shell__c.ApplicationId__c)}
&QVar3ID=a4G13000000LPCR?pv0={!JSENCODE(AFC_Contract_Shell__c.ApplicationId__c)}

&DocuSignR1Id={Qvar0}
&DocuSignR1Type=Signer
&DocuSignR1Role=Signer+1
&DocuSignR1RoutingOrder=2
&DocuSignR1AccessCode={!JSENCODE(AFC_Contract_Shell__c.eContract_Access_Code__c)}
&DocuSignR1IdCheck=1
&DocuSignR1IdCheckType=RSA

&DocuSignR2Id={Qvar1}
&DocuSignR2Type=Signer
&DocuSignR2Role=Signer+2
&DocuSignR2RoutingOrder=2
&DocuSignR2AccessCode={!JSENCODE(AFC_Contract_Shell__c.eContract_Access_Code__c)}
&DocuSignR2IdCheck=1
&DocuSignR2IdCheckType=RSA

&DocuSignR3Id={Qvar2}
&DocuSignR3Type=Signer
&DocuSignR3Role=Signer+3
&DocuSignR3RoutingOrder=2
&DocuSignR3AccessCode={!JSENCODE(AFC_Contract_Shell__c.eContract_Access_Code__c)}
&DocuSignR3IdCheck=1
&DocuSignR3IdCheckType=RSA

&DocuSignR4Id={Qvar3}
&DocuSignR4Type=Signer
&DocuSignR4Role=Signer+4
&DocuSignR4RoutingOrder=2
&DocuSignR4AccessCode={!JSENCODE(AFC_Contract_Shell__c.eContract_Access_Code__c)}
&DocuSignR4IdCheck=1
&DocuSignR4IdCheckType=RSA

&DocusignR5Id={!JSENCODE(AFC_Contract_Shell__c.AFC_eContract_Role__c)}
&DocuSignR5Type=Approver
&DocuSignR5Role=Approver+5
&DocuSignR5RoutingOrder=1
&DocuSignR5IdCheck=0

&DocusignR6Id={!JSENCODE(AFC_Contract_Shell__c.AFC_Branch_Console_Owner__c)}
&DocuSignR6Type=Approver
&DocuSignR6Role=Approver+6
&DocuSignR6RoutingOrder=6
&DocuSignR6IdCheck=0
');

I have a custom button that I'm using JavaScript to update a few fields and then process the above URL to open in a new window. I was trying window.location.href and window.open(), but both throw errors.

  • Please include the error text... – Adrian Larson Jun 17 '15 at 0:16
  • it was a syntax error...it did not give me any more detail with an error message. – Dman100 Jun 17 '15 at 0:27
  • do any of the values line "name" contain an apostrophe? – Eric Jun 17 '15 at 1:03
  • no apostrophe's, but there a double quotes. I'm trying to split each line into its own separate var and then concatenate together. Seems like I shouldn't have to do that, but I'm giving it a try. – Dman100 Jun 17 '15 at 1:07
  • 1
    Can you post the complete javascript? – Ashwani Jun 17 '15 at 4:54
1

Change following line

appObj.Id = {!AFC_Contract_Shell__c.ApplicationId__c};

to

appObj.Id = "{!JSENCODE(AFC_Contract_Shell__c.ApplicationId__c)}";

Also make sure that window.location.href does not contain any unclosed quote.

window.location.href = encodeURI('YOUR COMPLETE URL');

and put all {!expression} as {!JSENCODE(expression)}

  • I'm still getting unterminated string error. I'm checking on the unclosed quote. Do the double quotes need to be escaped? – Dman100 Jun 17 '15 at 12:08
  • @Dman100 Updated answer. – Ashwani Jun 17 '15 at 12:23
  • I've added encodeURI to the full URL and I've wrapped all merge field expressions with JSENCODE. I'm still getting un-terminated string issue. I've updated the full code above. Do you see anything I'm missing? – Dman100 Jun 17 '15 at 13:33
  • any other ideas what might be wrong with the URL? – Dman100 Jun 17 '15 at 23:47

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.