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
Jag SinghJag Singh 

Lead Convert Button Code Error

Hi,

I've created a new button so that I can convert Leads when they have a Time Based workflow running. However, I'm getting an error when click the button:

"Unexpected Token ILLEGAL" 

The code for my OnClick JavaScript button is:

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
var newRecords = [];
var c = new sforce.SObject(“Lead”);
c.id =”{!Lead.Id}”;
c.Cancel_Time_Based_Workflow__c = “TRUE”;
newRecords.push(c);
result = sforce.connection.update(newRecords);

window.parent.location.href=”/lead/leadconvert.jsp?id={!Lead.Id}&RetURL=/{!Lead.Id}”;



This happens when I actually click on the Convert button.

Thanks,
Jag
Best Answer chosen by Jag Singh
Abhishek_PareekAbhishek_Pareek
Try this:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
var newRecords = [];
var c = new sforce.SObject("Lead");
c.id ="{!Lead.Id}";
c.Cancel_Time_Based_Workflow__c = "TRUE";
newRecords.push(c);
result = sforce.connection.update(newRecords);

window.parent.location.href="/lead/leadconvert.jsp?id={!Lead.Id}&RetURL=/{!Lead.Id}";
Hope this helps!

All Answers

Jag SinghJag Singh
Code Updated: 

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
var newRecords = [];
var c = new sforce.SObject("Lead");
c.id ="{!Lead.Id}";
c.!Lead.Cancel_Time_Based_Workflow__c= "TRUE";
newRecords.push(c);
result = sforce.connection.update(newRecords);

window.parent.location.href="/lead/leadconvert.jsp?id={!Lead.Id}&RetURL=/{!Lead.Id}";

Now getting error: "Unexpected Token !"

Nearly there just needs tweaking, if anyone has any ideas that would be great! 

Thanks,
J


Abhishek_PareekAbhishek_Pareek
Try this:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
var newRecords = [];
var c = new sforce.SObject("Lead");
c.id ="{!Lead.Id}";
c.Cancel_Time_Based_Workflow__c = "TRUE";
newRecords.push(c);
result = sforce.connection.update(newRecords);

window.parent.location.href="/lead/leadconvert.jsp?id={!Lead.Id}&RetURL=/{!Lead.Id}";
Hope this helps!
This was selected as the best answer
Jag SinghJag Singh
Hi Abhishek,

I copied your code and this time the button actually works and moves me to the convert page of the lead. However, I thought the whole purpose was to bypass this as the error keeps appearing:

User-added image

Any idea what I'm doing wrong here?

J

Jag SinghJag Singh
Hi Abhishek,

I've got the Lead convert to work! :) 

I had another workflow on the Lead object that was also running, which I didn't delete! 

Thanks for your help!

Jag