+ Start a Discussion
Ramanarayanan PadmanabhanRamanarayanan Padmanabhan 

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


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(); 

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; 


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); 
var oppRecords1 = oppRecords.getArray('records'); 
//non_Sync = '{!Quote.Custom_isSync__c}' 
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; 
//activeQuote[a] = oppRecords1[a].Name; 
c = c + 1; 
//oppRecords[a].Custom_isSync__c = false; 

//alert (withStyle); 
var newVar = oppRecords1[0]; 

if(Quote2Update!= null) 


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?"); 
Quote2Update.Custom_isSync__c = 1; 
mes = "Quote Synchronized"; 
result = sforce.connection.update(Quote3Update_Array); 

mes = "Quote Not Synchronized"; 

else if (is_sync==0) 

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


mes = "Quote Not Synchronized anymore"; 

updateQuote = sforce.connection.update([Quote2Update]); 


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