+ Start a Discussion
Victor19Victor19 

Custom Javascript button for approval process - display multiple error messages

Hi, 
I have a javascript which when clicked checks fields 1 and fields 2 and if both the fields are blank or if one of them is blank, an error message
is shown on the page. The issue I am having now is the error messages are getting displayed but they are appearing in 2 different pop ups if both fields are blanks. I would like to display both those error messages in the same popup window.

if ('{!Quote.Field1__c}' == '') {
alert('Field1 cannot be blank');
}
else if ('{!Quote.Field2__c}' == '') {
alert('Field2 cannot be blank');
}
else{
navigateToUrl('/p/process/Submit?retURL=%2F{!Quote.Id}&id={!Quote.Id}');
}



I would really appreciate if someone could please help me out
SonamSonam (Salesforce Developers) 
Update it as below and test:

if (('{!Quote.Field1__c}' == '') &&('{!Quote.Field2__c}' != '') ) {
alert('Field1 cannot be blank');
}
else if (('{!Quote.Field2__c}' == '') &&('{!Quote.Field1__c}' != '') ) {
alert('Field2 cannot be blank');
}
else if (('{!Quote.Field2__c}' == '') &&('{!Quote.Field1__c}' == '') ) {
alert('Both fields cannot be blank');
}
else{
navigateToUrl('/p/process/Submit?retURL=%2F{!Quote.Id}&id={!Quote.Id}');
}