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
Vandana RattanVandana Rattan 

Error generating Quote PDF from JS button

I have created a List JS button in Opportunity Page > Quote Related List to generate Quote PDF for the selected Quote record. I get PdfOverlay undefined and after that a message is displayed "Cannot read Property 'dialog' of undefined. Below is my code:-

{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}

records = {!GETRECORDIDS($ObjectType.Quote)};
alert('records > ' + records);
var selectedRecords = [records];
alert('selectedRecords>' + selectedRecords);


var pdfOverlay = QuotePDFPreview.quotePDFObjs['quotePDFOverlay'];

alert('pdfOverlay > ' + pdfOverlay);

pdfOverlay.dialog.buttonContents = '<input value=\"Save to Quote\"  class=\"btn\" name=\"save\" onclick=\"QuotePDFPreview.getQuotePDFObject(\'quotePDFOverlay\').savePDF(\'0\',\'0\');\" title=\"Save to Quote\" type=\"button\" /><input value=\"Save and Email Quote\"  class=\"btn\" name=\"saveAndEmail\" onclick=\"QuotePDFPreview.getQuotePDFObject(\'quotePDFOverlay\').savePDF(\'1\');\" title=\"Save and Email Quote\" type=\"button\" /><input value=\"Cancel\"  class=\"btn\" name=\"cancel\" onclick=\"QuotePDFPreview.getQuotePDFObject(\'quotePDFOverlay\').close();\" title=\"Cancel\" type=\"button\" />';



 //change this to use the correct template for your business/environment!! 
pdfOverlay.summlid = '0EH90000000Gdtu'; 

 pdfOverlay.setSavable(true); 

 //change this to use the quote id 
pdfOverlay.setContents('/quote/quoteTemplateDataViewer.apexp?id={!Quote.Id}','quote/quoteTemplateHeaderData.apexp?id={!Quote.Id}'); 

 pdfOverlay.display();

Kindly suggest some soln.
bob_buzzardbob_buzzard
This suggests that the QuotePDFPreview.quotePDFObjs array is empty. Where does this array get set up in your page? You may be able to output a text representation of the QuotePDFPreview object using the JSON.stringify method.
Kailash SatiKailash Sati
You are using too many ( / )

Just copy this and it should work.

var pdfOverlay = QuotePDFPreview.quotePDFObjs['quotePDFOverlay']; 
pdfOverlay.dialog.buttonContents = '<input value=\"Save to Quote\" class="btn" name="save" onclick="QuotePDFPreview.getQuotePDFObject(\'quotePDFOverlay\').savePDF(\'0\',\'0\');" title="Save to Quote" type="button" /><input value="Save and Email Quote" class="btn" name="saveAndEmail" onclick="QuotePDFPreview.getQuotePDFObject(\'quotePDFOverlay\').savePDF(\'1\');" title="Save and Email Quote" type="button" /><input value="Cancel" class="btn" name="cancel" onclick="QuotePDFPreview.getQuotePDFObject(\'quotePDFOverlay\').close();" title="Cancel" type="button"/>'; 
pdfOverlay.summlid = 'Your Template ID Here'; 
pdfOverlay.setSavable(true); 
pdfOverlay.setContents('/quote/quoteTemplateDataViewer.apexp?id={!Quote.Id}','quote/quoteTemplateHeaderData.apexp?id={!Quote.Id}'); 
pdfOverlay.display();
Dimitris MDimitris M
Hello can you give me an example with what value can I use in Quote.Id
pdfOverlay.setContents('/quote/quoteTemplateDataViewer.apexp?id={!Quote.Id}
bob_buzzardbob_buzzard
This would be the id of a quote record. If you navigate to a quote record, you can find the id at the end of the URL, so in the following URL:

https://kabtutorial-developer-edition.my.salesforce.com/0Q080000000H74E

the quote id is : 0Q080000000H74E

 
Dimitris MDimitris M
Hello Bob, 

If use a hard coded Quote.Id I suppose that it will not work for all the other Quotes.
I need to create a custom button which is using a predefined template.

see below the code that I used from this post.

but I got the following error:
User-added image


by the way did you manage to replicate this custom button on your sandbox?

Thanks in advance
Dimitri

{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}


var pdfOverlay = QuotePDFPreview.quotePDFObjs['quotePDFOverlay']; 
pdfOverlay.dialog.buttonContents = '<input value=\"Save to Quote\" class="btn" name="save" onclick="QuotePDFPreview.getQuotePDFObject(\'quotePDFOverlay\').savePDF(\'0\',\'0\');" title="Save to Quote" type="button" /><input value="Save and Email Quote" class="btn" name="saveAndEmail" onclick="QuotePDFPreview.getQuotePDFObject(\'quotePDFOverlay\').savePDF(\'1\');" title="Save and Email Quote" type="button" /><input value="Cancel" class="btn" name="cancel" onclick="QuotePDFPreview.getQuotePDFObject(\'quotePDFOverlay\').close();" title="Cancel" type="button"/>'; 
pdfOverlay.summlid = "0EHb0000000VEWc"; 
pdfOverlay.setSavable(true); 
pdfOverlay.setContents('/quote/quoteTemplateDataViewer.apexp?id={!Quote.Id}','quote/quoteTemplateHeaderData.apexp?id="0Q0b0000000JNzn"'); 
pdfOverlay.display();


 
Bailey RuddBailey Rudd
I'm trying to use this same type of code for selecting a quote template, and I am receiving similiar error. Was this ever resolved on your end?