I'm trying to edit a custom OnClick JS button which creates a PDF from a quote, provided the quote passes certain checks.
this code works:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var q = new sforce.SObject("Quote");
q.id = "{!Quote.Id}";
q.Status = "Presented";
result = sforce.connection.update([q]);
if('{!Quote.Status}'!= 'Cancelled'&&{!ISNULL(Quote.Invoice_Address_Lines__c)=FALSE}&&{!ISNULL(Quote.Invoice_Address_Country__c)=FALSE})
{
do some business logic here...
var isOk = true;
} if(isOk)
{
var pdfOverlay = QuotePDFPreview.quotePDFObjs['quotePDFOverlay'];
pdfOverlay.dialog.buttonContents = "<input value=\'Save to Invoice Overview\' class=\'btn\' name=\'save\' onclick=\"QuotePDFPreview.getQuotePDFObject(\'quotePDFOverlay\').savePDF(\'0\',\'0\');\" title=\'Save to Quote\' type=\'button\' ><input value='Save and Email' 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!!
//TB: This has been adapted to choose the correct template based on the result Quote_Template_ID__c returns
pdfOverlay.summlid = '{!Quote.Quote_Template_ID__c}';
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();
}
else
{
//raise an alert to let the user know about some business rule
alert('Invoices must have an Address and Country specified and cancelled Invoices cannot be regenerated.');
}
I need to edit the initial "if" to add a check for a situation where the invoice in question is marked as needing a VAT number (VAT_Number_Invoice__c) AND the VAT number (VAT_Number__c) is blank.
I'm replacing
if('{!Quote.Status}'!= 'Cancelled'&&{!ISNULL(Quote.Invoice_Address_Lines__c)=FALSE}&&{!ISNULL(Quote.Invoice_Address_Country__c)=FALSE})
{
with
if(
'{!Quote.Status}'!= 'Cancelled'&&
{!ISNULL(Quote.Invoice_Address_Lines__c)=FALSE}&&
{!ISNULL(Quote.Invoice_Address_Country__c)=FALSE}&&
(
{!ISNULL(Quote.VAT_Number__c)=FALSE} ||
'{!Quote.VAT_Number_Invoice__c}' = 'FALSE')
)
{
or variations on this. I cant seem to get past left hand side alignment errors, or the code just not picking up the last condition.
Has anyone got any ideas how to get this code working? Am I doing anything obviously wrong?
essentially: build the PDF if (1 isnt blank AND 2 isnt blank AND 3 isnt blank AND (4 isnt blank OR 5 is false))