5

I have a custom field on quote which is a checkbox. I need a way to allow or disallow the pdf creation based on this field

If the checkbox is true then only allow the create pdf to fire otherwise give a alert to say need to set the checkbox to true.

Is there a way to call the standard functionality of create Pdf button? I can check the custom field value on Quote in javascript and based on it call the create pdf button functionality.

Any ideas how we can achieve this?

2 Answers 2

4

Do you have a custom controller for your Quote PDF generator? If not, you can easily create one by creating an extension of the existing one that has a boolean object linked to a checkbox. If the checkbox is true, then the PDF is created, if it's false, then the PDF is aborted. Before any work is done, the controller checks the status of the custom boolean object.

I'm sure you could similarly add that kind of logic into the VF page by adding a validation rule to the checkbox, but I've never done it that way myself. Or, as you've suggested, this could also be done via JavaScript by checking the state of the checkbox.

6
  • I am not sure if i understood what you are saying.. Which class should i create an extension of ? Quote? I have not used a custom controller to create the pdf, but want to somehow try to use the standard functionality of pdf generation
    – Prady
    Apr 2, 2013 at 7:32
  • You'd create an extension of the standard controller. For more info on how PDF's are generated, you might want to start at this link which is part of the Visual Force documentation: salesforce.com/us/developer/docs/pages/Content/….
    – crmprogdev
    Apr 2, 2013 at 14:30
  • You might also find the following tutorial helpful. Its called Creating Professional PDF Documents with CSS and VisualForce.
    – crmprogdev
    Apr 2, 2013 at 15:50
  • Oh!! what you are suggesting is that i create a VF page and renderas = pdf? That was the first thing i tried to do but the complexity of getting screen like the standard Quotes createPDF functionality put me of.. I ended up using the javasript which was been used by create PDF button and added my check in the javascript itself. I have added it up as an answer
    – Prady
    Apr 3, 2013 at 4:18
  • @Prady. Yes, that's exactly what I was recommending. Essentially, you write a custom HTML page that creates the form as you want it to appear. You then use the button to have it render in a new window. It never has to appear in a standard VF page and can look exactly how you'd like to appear, just as an email or any other document would (including the VF page you've started from). Its much easier than it sounds if you have any HTML or VF page skills at all.
    – crmprogdev
    Apr 3, 2013 at 6:21
4

The way i handled this was by using the same javascript used in the standard create pdf button.

Note you would need to change the summlid( which is the quotes templateId) This is hardcoded for now. Not sure if we can get the id of this dynamically

if("{!Quote.Needs_Approval__c}" == true)
{
  alert('Pls submit this Quote for approval');
}
else
{
 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 = '0EH900000009lyR'; // This is the template id for quotes, we would need to change this value according to the environment we are adding this button into
 pdfOverlay.setSavable(true);

 pdfOverlay.setContents('/quote/quoteTemplateDataViewer.apexp?id=' +"{!Quote.Id}",'/quote/quoteTemplateHeaderData.apexp?id='+"{!Quote.Id}");
pdfOverlay.display();
}

NOTE I cant say this is a best way of doing it... I have tested this only in dev env and it works.. Maybe the community could judge if this is one of the right way of doing it

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .