1

I have a custom button that displays an alert message when some fields on my object are missing. I would like to now also display the fields that are missing as part of that alert. I tried the code below, but it only shows the last field missing. How can I get the 1st alert along with any of the other alerts that are applicable? For example, I would want the alert to read:

Please complete the Approval Request Information section before submitting this Quote for approval. The following fields are missing:

Missing Offer Scope Missing Justification for Discounting

Javascript Button:

{!RequireScript("/soap/ajax/38.0/connection.js")} 
if('{!SBQQ__Quote__c.Offer_Scope__c }' == '' || '{! SBQQ__Quote__c.Justification_for_Discounting__c}' == '' || '{! SBQQ__Quote__c.Client_Background__c }' == '' || '{! SBQQ__Quote__c.Non_Standard_Terms__c }' == '' ) 
{ 
alert('Please complete the Approval Request Information section before submitting this Quote for approval. The following fields are missing:'); 

/* if('{!SBQQ__Quote__c.Offer_Scope__c }' == ''){ 
alert('Missing Offer Scope'); 
} 
if('{!SBQQ__Quote__c.Justification_for_Discounting__c }' == ''){ 
alert('Missing Justification for Discounting'); 
} 
if('{!SBQQ__Quote__c.Client_Background__c }' == ''){ 
alert('Missing Client Background'); 
} 
if('{!SBQQ__Quote__c.Non_Standard_Terms__c }' == ''){ 
alert('Missing Non-Standard Terms Indicator'); 
}*/ 
} 
else { 
window.top.location.href = "{!URLFOR($Action.SBQQ__Quote__c.Submit, SBQQ__Quote__c.Id )}"; 
}
4

The issue is that you are calling the alert function before you determined which fields are empty. You need to create a variable where you build up the message containing the missing fields, then at the end call alert and pass in the message variable:

{!RequireScript("/soap/ajax/38.0/connection.js")} 
if('{!SBQQ__Quote__c.Offer_Scope__c }' == '' || '{! SBQQ__Quote__c.Justification_for_Discounting__c}' == '' || '{! SBQQ__Quote__c.Client_Background__c }' == '' || '{! SBQQ__Quote__c.Non_Standard_Terms__c }' == '' ) 
{
    var message = 'Please complete the Approval Request Information section before submitting this Quote for approval. The following fields are missing: ';

    if('{!SBQQ__Quote__c.Offer_Scope__c }' == ''){ 
        message += '\nMissing Offer Scope';
    } 
    if('{!SBQQ__Quote__c.Justification_for_Discounting__c }' == ''){ 
        message += '\nMissing Justification for Discounting';
    } 
    if('{!SBQQ__Quote__c.Client_Background__c }' == ''){ 
        message += '\nMissing Client Background'; 
    } 
    if('{!SBQQ__Quote__c.Non_Standard_Terms__c }' == ''){ 
        message += '\nMissing Non-Standard Terms Indicator';
    }
    alert(message);
} 
else { 
    window.top.location.href = "{!URLFOR($Action.SBQQ__Quote__c.Submit, SBQQ__Quote__c.Id )}"; 
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.