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
Richard Pitfield 10Richard Pitfield 10 

Custom Javascript Button that worked for months has stopped working?


Hi there,

Below is some code I have in a custom button to tick a checkbox that runs a workflow rule

It has worked for almost a year and has now jut stopped working and I don't know why.

It runs the alerts but doesn't check the faculty Trial request box anymore, any help appreciated.

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
var newRecords = [];
var c = new sforce.SObject("Lead");
console.log("{!Lead.Faculty_Trial_test__c}");
if
("{!Lead.Faculty_Trial_test__c}" == "no")
{
alert("You can only request a Faculty Trial to SRM, Business or SAGE Video products. Plesae make sure you have added at least one of these products to the related Opportunity.");
}
if("{!Lead.Department__c}" == "")
{
alert("You must add a Department to request a Faculty Trial.");
}
if
("{!Lead.Email}" == "")
{
alert("You must add an Email to request a Faculty Trial.");
}
else
{
c.id ="{!Lead.Id}";
c.Faculty_Trial_Request__c = false;
c.Faculty_Trial_Request__c = true;
newRecords.push(c);
result = sforce.connection.update(newRecords);
window.location.reload();}
Best Answer chosen by Richard Pitfield 10
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi Richard, 

Please try this, 
 
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}

var newRecords = [];
var c = new sforce.SObject("Lead");
console.log("{!Lead.Faculty_Trial_test__c}");
if("{!Lead.Faculty_Trial_test__c}" == "no") {
	alert("You can only request a Faculty Trial to SRM, Business or SAGE Video products. Plesae make sure you have added at least one of these products to the related Opportunity.");
}
if("{!Lead.Department__c}" == "") {
	alert("You must add a Department to request a Faculty Trial.");
}
if("{!Lead.Email}" == "") {
	alert("You must add an Email to request a Faculty Trial.");
}
else {
	c.id ="{!Lead.Id}";
	c.Faculty_Trial_Request__c = false;
	c.Faculty_Trial_Request__c = true;
	newRecords.push(c);
	result = sforce.connection.update(newRecords);
	window.location.reload();
}

You have missed {!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")} i suppose.

Thanks, 
Prosenjit

All Answers

Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi Richard, 

Please try this, 
 
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}

var newRecords = [];
var c = new sforce.SObject("Lead");
console.log("{!Lead.Faculty_Trial_test__c}");
if("{!Lead.Faculty_Trial_test__c}" == "no") {
	alert("You can only request a Faculty Trial to SRM, Business or SAGE Video products. Plesae make sure you have added at least one of these products to the related Opportunity.");
}
if("{!Lead.Department__c}" == "") {
	alert("You must add a Department to request a Faculty Trial.");
}
if("{!Lead.Email}" == "") {
	alert("You must add an Email to request a Faculty Trial.");
}
else {
	c.id ="{!Lead.Id}";
	c.Faculty_Trial_Request__c = false;
	c.Faculty_Trial_Request__c = true;
	newRecords.push(c);
	result = sforce.connection.update(newRecords);
	window.location.reload();
}

You have missed {!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")} i suppose.

Thanks, 
Prosenjit
This was selected as the best answer
Richard Pitfield 10Richard Pitfield 10
That worked a treat Prosenjit thanks!