function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ajinkya ShahaneAjinkya Shahane 

I want a custom button for setting up a task and activities for voice Email activity, I am done with this code but getting an error while changing the status from open - not contacted to open voice Email

Error -
A problem with the OnClick JavaScript for this button or link was encountered:missing ; before statement

setting for custom button

Setting
Display Type    
Detail Page Button View example

Behavior
Execute java script

content source
Onclick javascript

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

try{
    var taskToCreate = new sforce.SObject("Task");
    taskToCreate.OwnerId = "{!$User.Id}";
    taskToCreate.WhoId = "{!Lead.Id}";
    taskToCreate.Subject = "Voicemail";
    taskToCreate.ActivityDate = new Date();

    taskToCreate.Priority = "Normal";
    taskToCreate.Status = "Completed";

taskToCreate.Division__c = "Verdantis";
    result = sforce.connection.create([taskToCreate]);

var newRecords = [];
 var leadstatusupdate = new sforce.SObject("Lead");
  leadstatusupdate.Lead ID = "{!Lead.Id}";
 leadstatusupdate.Status = "Open - Voicemail / Email";
  result = sforce.connection.update([leadstatusupdate]);
if(
"{!Lead.Status}" === "Open - Not Contacted" ||
"{!Lead.Status}" === "Archive" &&
"{!Lead.Archive_Reason__c}" === "No Plans - Till Next 6 months" ||
"{!Lead.Archive_Reason__c}" === "No Plans - Till Next year"
){
leadstatusupdate.Status = "Open - Voicemail / Email";
}

newRecords.push(leadstatusupdate);

result = sforce.connection.update(newRecords);

    if(result[0].success == "true"){
        location.reload();
    }
    else{
        alert(
            "An Error has Occurred. Error: \r\n" +
            result[0].errors.message
        );
    }
}
catch(e){{!BMCServiceDesk__Task__c.BMCServiceDesk__DisplayInSS__c}
    alert(
        "An Un-expected Error has Occurred. Error: \r\n" +
        e
    );
}

 
Bhupendra Kshatri 6Bhupendra Kshatri 6
Could you group yyour condition properly using the brackets?
"{!Lead.Status}" === "Open - Not Contacted" ||
"{!Lead.Status}" === "Archive" &&
"{!Lead.Archive_Reason__c}" === "No Plans - Till Next 6 months" ||
"{!Lead.Archive_Reason__c}" === "No Plans - Till Next year"
)
Use == instead of ===
Ajinkya ShahaneAjinkya Shahane
Thanks for replying,
Even though I have used the == but getting same error though