1

I can't understand why this Javascript button doesn't work.

I keep getting an error: "Invalid or unexpected token"

Can anyone see why this is?

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

var records = [];

var opp = new sforce.SObject("Opportunity");
    opp.Id = "{!Opportunity.Id}";

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1;
var yyyy = today.getFullYear();

if (dd < 10) {
        dd = '0' + dd;
    }
    if (mm < 10) {
        mm = '0' + mm;
    }

opp.Docusign_Send_Date__c = dd + '/' + mm + '/' + yyyy;

var result = sforce.connection.update([records]);

if(result[0].success === "true"){
    window.location = '/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID={!Opportunity.Id}';
}
else{
    alert(
        "An Error has Occurred. Error: " +
        result[0].errors.message
    );
}
}

catch(e){
    alert(
      "An unexpected Error has Occurred. Error: " + e
      );
}

1 Answer 1

1

It appears there is an extra brace( } ) after your else statement. You also need a try to go along with the catch.

1
  • Not sure how I didn't spot that! Thanks so much! Sometimes it's the simple things. Commented Sep 21, 2019 at 0:11

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.