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
Ramanarayanan PadmanabhanRamanarayanan Padmanabhan 

OnClick custom Quote javascript button not working for a specific Recordtype.

Hi,

We have a custom javascript button on quote which replaces the standard sync functionality of quotes. Apart from that we have added some code to display inactive products in quote line items . If the quote line items has inactive products it shows an alert with Inactive product and will not be synchronized. The custom button works fine except one RecordType. When the quote's status is Won, It is changed to a custom_won_RT. 

On Clicking that button, It's throwing the following error: User-added image

The js code:

var Quote2Update = new sforce.SObject("Quote"); 
Quote2Update.id= "{!Quote.Id}"; 
var strQuery = "select Product2.Name,Id,quote.name,Product2.IsActive from QuoteLineItem where quote.id = " + "'" + Quote2Update.id + "'"; 
var records = sforce.connection.query(strQuery); 
var records1 = records.getArray('records'); 
var active = new Array(); 
var inactiveProd = new Array(); 
var withStyle = new Array(); 
is_sync='{!Quote.Custom_isSync__c}' 

for(var i = 0, j = 0; i < records1.length; i++) 

if(records1[i].Product2.IsActive == 'false') 

inactiveProd[j] = records1[i].Product2.Name; 
j = j + 1; 


//alert(inactiveProd); 

for(var k=0;k < inactiveProd.length;k++) 


withStyle[k] = '\n'+'->'+inactiveProd[k]; 


var Quote3Update = new sforce.SObject("Quote"); 
Quote3Update.Opportunity_Name__c = "{!Quote.Opportunity_Name__c}"; 
var strQuery1 = "select Name,Id,Custom_isSync__c from quote where Quote.Opportunity_Name__c = " + "'" + Quote3Update.Opportunity_Name__c + "' and Custom_isSync__c = true"; 
var oppRecords = sforce.connection.query(strQuery1); 
//alert(oppRecords); 
var oppRecords1 = oppRecords.getArray('records'); 
//alert(oppRecords1); 
//non_Sync = '{!Quote.Custom_isSync__c}' 
//alert(non_Sync); 
var activeQuote = new Array(); 
var Quote3Update_Array = new Array(); 
for(var a=0;a<oppRecords1.length;a++) 

activeQuote[a] = oppRecords1[a].Name; 
//oppRecords[a].Custom_isSync__c = false; 

/****for(var b=0,c=0;b<oppRecords1.length;a++) 

var totalArray = oppRecords1[b]; 
totalArray.Custom_isSync = 0; 
Quote3Update_Array.push(totalArray); 
//activeQuote[a] = oppRecords1[a].Name; 
c = c + 1; 
//oppRecords[a].Custom_isSync__c = false; 
}***/ 

//alert(activeQuote); 
//alert (withStyle); 
//alert(activeProd); 
if(oppRecords1[0]){ 
var newVar = oppRecords1[0]; 
//alert(newVar.Custom_isSync__c); 
newVar.Custom_isSync__c=0; 
Quote3Update_Array.push(newVar); 

if(Quote2Update!= null) 

try 


if(is_sync==0 && inactiveProd.length==1) 

mes = "Quote could not be synchronized since the Product "+withStyle+" is inactive."; 

else if(is_sync==0 && inactiveProd.length>1) 

mes = "Quote could not be synchronized since the Products "+withStyle+" are inactive."; 

else if (is_sync==0 && activeQuote.length>0) 


var bool=confirm("The Quote "+activeQuote+" is already Synchronized.Do you wish to continue?"); 
if(bool){ 
Quote2Update.Custom_isSync__c = 1; 
mes = "Quote Synchronized"; 
result = sforce.connection.update(Quote3Update_Array); 

else{ 
mes = "Quote Not Synchronized"; 


else if (is_sync==0) 

Quote2Update.Custom_isSync__c = 1; 
mes = "Quote Synchronized"; 
result = sforce.connection.update(Quote3Update_Array); 

else 

Quote2Update.Custom_isSync__c=0 
mes = "Quote Not Synchronized anymore"; 

updateQuote = sforce.connection.update([Quote2Update]); 
alert(mes); 
window.location.reload(); 

catch(e) 

alert('error : ' + e); 

}

Any suggestion to resolve this error?
ShashankShashank (Salesforce Developers) 
Please see if this helps you: http://salesforce.stackexchange.com/questions/36333/trouble-with-after-update-trigger-for-quote-line-item