Skip to main content
I have created a custom button and am getting the error "expected expression, got ')'

Here is the code I'm using. I have highlighted the section where I believe the error is occurring.

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

 

var agree = confirm("Ok to Submit this Project Number Request to Finance?");

 

    if (agree) {

        // Ok case

        //alert('OK pressed');

        var myquery = "SELECT Id,  Start_Date__c  FROM Engagements__c WHERE Id =           '{!Engagements__c.Id}' limit 1";

        result = sforce.connection.query(myquery);

        records = result.getArray("records");

        var myEng = records[0];

        var updateEng = new Array();

        if({!Engagements__c.IB_M_A_Engagement__c}){

           myEng.RecordTypeId = '012g00000001NfX';

        } else  {

           myEng.RecordTypeId = '012j00000019Sga';

        }

 

        myEng.Prj_Request_Sent_to_Finance__c = true;

        myEng.Project_Code_Status__c = 'Project Code Requested, Check Your Email';

        updateEng.push(myEng);

        result = sforce.connection.update(updateEng);

        if(result[0].getBoolean("success")){

           alert('Project Code Request has been sent to Finance... Check your Email in the next 24 hours');

           window.location = "/" + "{!Engagements__c.Id}";

        }

 
1 件の回答
  1. 2017年9月9日 16:06
    1) Two REQUIRESCRIPTnormally: 

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

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

    2) It lacks the last "}" at the end (incomplete copy/paste)

    3) Avoid new Array()

    There is no need to use the JavaScript's built-in array constructor new Array().

    Use [] instead.

    These two different statements both create a new empty array named points:

    var points = new Array();    // Bad

    var points = [];                  // Good 

    These two different statements both create a new array containing 6 numbers:

    var points = new Array(40, 100, 1, 5, 25, 10); // Bad

    var points = [40, 100, 1, 5, 25, 10];          // Good

    https://www.w3schools.com/js/js_arrays.asp

    First modifications before the next step and the final solution (if it is not fixed yet, so provide your own solution)

    Regards