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
Jitender  PaddaJitender Padda 

JavaScript timeout error: DOM exception 23

I am seeing this error while clicking on button with Onclick Javascript written in it. Could somebody please help me out a bit? I have posted a screenshot below.
screenshot.User-added image
Best Answer chosen by Jitender Padda
Jitender  PaddaJitender Padda
Fixed but the only possible explaination i could come up with was that the code was too lengthy and it was a timeout error.

All Answers

Jitender  PaddaJitender Padda
Here is the code for the Button - 
{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")} 
var updateRecord = new Array(); 
var sfdcSessionId = "{!GETSESSIONID()}"; 
var query="Select Id,Submission_Indicator__c From Sales_Order_Line__c where Sales_Order__c='"+"{!Sales_Order__c.Id}"+"'"; 

var queryResult = sforce.connection.query(query); 
var records = queryResult.getArray('records'); 

var Type="{!Sales_Order__c.Type__c}"; 
var oppId="{!Sales_Order__c.OpportunityId__c}"; 

if(Type=="Prebuild") 

<!--sforce.apex.execute("EmailSubmitToOAbutton","SendEmailAlert", {SOid:'{!Sales_Order__c.Id}'});--> 

var squery=sforce.connection.query("Select ID from Prebuild__c where Opportunity__c='"+oppId+"'") 
var prebuildRecord=squery.getArray('records'); 
var prebuildRecordOne=prebuildRecord[0]; 
if(prebuildRecord.length>0) 

if(records.length!=0) 

for(i=0;i<records.length;i++) 

var update_sales_line = records[i]; 
update_sales_line.Submission_Indicator__c= true; 
updateRecord.push(update_sales_line); 


result = sforce.connection.update(updateRecord); 
//parent.location.href = parent.location.href; 

var SO = new sforce.SObject("Sales_Order__c"); 

SO.Id="{!Sales_Order__c.Id }"; 

SO.Status__c="{!Sales_Order__c.Status__c}"; 


if ( SO.Status__c == "Submitted to OA" || SO.Status__c=="Approved by OA") 

alert("Resubmission is not allowed for SalesOrder with Status as Approved by OA or Submitted to OA"); 


else 

SO.Status__c="Submitted to OA"; 




function padzero(n) { 
return n < 10 ? '0' + n : n; 


function pad2zeros(n) { 
if (n < 100) { 
n = '0' + n; 

if (n < 10) { 
n = '0' + n; 

return n; 


function toISOString(d) { 
return d.getUTCFullYear() + '-' + padzero(d.getUTCMonth() + 1) + '-' + padzero(d.getUTCDate()) + 'T' + padzero(d.getUTCHours()) + ':' + padzero(d.getUTCMinutes()) + ':' + padzero(d.getUTCSeconds()) + '.' + pad2zeros(d.getUTCMilliseconds()) + 'Z'; 


var now = new Date(); 
SO.Last_Submission_DateTime__c = toISOString(now); 

if(SO!=null) 

try 

updateSO = sforce.connection.update([SO]); 
window.location.reload(); 


catch(e) 

alert("error : " + e); 




}else 

alert("Prebuild Order Type is allowed only for opportunities with Prebuild request"); 


else 


if(records.length!=0) 

for(i=0;i<records.length;i++) 

var update_sales_line = records[i]; 
update_sales_line.Submission_Indicator__c= true; 
updateRecord.push(update_sales_line); 


result = sforce.connection.update(updateRecord); 
//parent.location.href = parent.location.href; 

var SO = new sforce.SObject("Sales_Order__c"); 

SO.Id="{!Sales_Order__c.Id }"; 

SO.Status__c="{!Sales_Order__c.Status__c}"; 


if ( SO.Status__c == "Submitted to OA" || SO.Status__c=="Approved by OA") 

alert("Resubmission is not allowed for SalesOrder with Status as Approved by OA or Submitted to OA"); 


else 

SO.Status__c="Submitted to OA"; 




function padzero(n) { 
return n < 10 ? '0' + n : n; 


function pad2zeros(n) { 
if (n < 100) { 
n = '0' + n; 

if (n < 10) { 
n = '0' + n; 

return n; 


function toISOString(d) { 
return d.getUTCFullYear() + '-' + padzero(d.getUTCMonth() + 1) + '-' + padzero(d.getUTCDate()) + 'T' + padzero(d.getUTCHours()) + ':' + padzero(d.getUTCMinutes()) + ':' + padzero(d.getUTCSeconds()) + '.' + pad2zeros(d.getUTCMilliseconds()) + 'Z'; 


var now = new Date(); 
SO.Last_Submission_DateTime__c = toISOString(now); 

if(SO!=null) 

try 

updateSO = sforce.connection.update([SO]); 
window.location.reload(); 


catch(e) 

alert("error : " + e); 



}
Jitender  PaddaJitender Padda
Fixed but the only possible explaination i could come up with was that the code was too lengthy and it was a timeout error.
This was selected as the best answer
YogeshSource SharmaYogeshSource Sharma

Hello Jitender,

I am facing the same problem. Could you please share the solution here?

Thanks,

Yogesh Sharma

Jitender  PaddaJitender Padda

Hi Yogesh,

Like I mentioned in the answer above, the only reason I could figure out was that the code was taking too long to execute. Suggestions would be to shorten the code or move some of the logic to a trigger maybe (I did this in my case).

Thanks,
Jitender