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
dani a.ax940dani a.ax940 

Javascript error on Custom button click

Hi,
I am using one custom list button on one of the related list. But sometime when I click on this button I am getting the below error message:
A problem with the OnClick javascript for this button or link was encountered: Failed to execute send on 'XMLHttprequest': Failed to load 'https://cs21.salesforce.com/services/Soap/u/29.0'.

One thing to note here is that this error message is not coming all the time. But I need to fix this one. Below is my JS code for this button:

{! REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
var RecordTypeQuery = "Select Id from RecordType where developername='Set_Up_Plan' and SObjectType='Activity_Plan__c'";
var recordtype= sforce.connection.query(RecordTypeQuery );
var records = recordtype.getArray("records");
window.open("/{!$Setup.Org_Level_Settings__c.Activity_Plan_Prefix__c}/e?CF{!$Setup.Org_Level_Settings__c.Activity_Plan_ICP_Field_Id__c}={!JSENCODE(Account.Name)}&CF{!$Setup.Org_Level_Settings__c.Activity_Plan_ICP_Field_Id__c}_lkid={!Account.Id}&RecordType="+records[0].Id+"&retURL={!Account.Id}","_parent");

Any help is much appreciated. Thanks in advance.
Darshan Shah2Darshan Shah2
Hello dani a.ax940,

Update the version of your connection.js as shown below:
{! REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}

Let me know whether it helps to solve your problem
OR
Let me know the cause so I can try to solve :)

Warm Regards,
Darshan Shah
Amit Chaudhary 8Amit Chaudhary 8
Please try below code :-
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")} 

var RecordTypeQuery = sforce.connection.query("Select Id from RecordType where developername='Set_Up_Plan' and SObjectType='Activity_Plan__c'" ); 
var record = RecordTypeQuery.getArray("records")[0];
// alert('record'+record); please use alert to check value of code will nt work

window.open("/{!$Setup.Org_Level_Settings__c.Activity_Plan_Prefix__c}/e?CF{!$Setup.Org_Level_Settings__c.Activity_Plan_ICP_Field_Id__c}={!JSENCODE(Account.Name)}&CF{!$Setup.Org_Level_Settings__c.Activity_Plan_ICP_Field_Id__c}_lkid={!Account.Id}&RecordType="+record.Id+"&retURL={!Account.Id}","_parent");