+ Start a Discussion
Bogdan PascuBogdan Pascu 

Validation rule on custom button Hi

I have this custom button with Javascript that is working perfectly fine: 

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

if ({!pba__Offer__c.pba__SystemIsCancelled__c}) { 
alert("{!$Label.pba__Offer_ErrorAlreadyCancelled}"); 
} else { 

if (confirm("{!$Label.pba__Offer_ConfirmCancellation}")) { 

var updateSobject = new sforce.SObject("pba__Offer__c"); 

try { 

updateSobject.Id = "{!pba__Offer__c.Id}" ; 
updateSobject.pba__SystemIsCancelled__c = true; 

result = sforce.connection.update([updateSobject]); 
if (result[0].getBoolean("success")) { 
location.reload(true); 
} else { 
alert("{!$Label.pba__Generic_ErrorOccured}: " + result[0].errors.message); 


} catch(e) { 
alert("{!$Label.pba__Generic_ErrorOccured}: " + e); 




}


I want to include an additional line to this code, can you please help me on where this new line should go:

if (ISBLANK({!pba__Offer__c.Offer_canceled_comments__c}) { 
alert ("Please specify the reason why the Offer has been canceled!!!!"); 
} else { 
Best Answer chosen by Bogdan Pascu
RaidanRaidan
Sorry, I missed the ''
if ('{!pba__Offer__c.Offer_canceled_comments__c}' == '') {

 

All Answers

RaidanRaidan
I think it should be before this line:

if (confirm("{!$Label.pba__Offer_ConfirmCancellation}")) { 

Don't forget to add a closing '}' at the end.
Veenesh VikramVeenesh Vikram
Hi,

I guess this is what you are looking for:
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")} 

if ({!pba__Offer__c.pba__SystemIsCancelled__c}) { 
alert("{!$Label.pba__Offer_ErrorAlreadyCancelled}"); 
} else { 
if (ISBLANK({!pba__Offer__c.Offer_canceled_comments__c}) { 
alert ("Please specify the reason why the Offer has been canceled!!!!"); 
} else {
if (confirm("{!$Label.pba__Offer_ConfirmCancellation}")) { 

var updateSobject = new sforce.SObject("pba__Offer__c"); 

try { 

updateSobject.Id = "{!pba__Offer__c.Id}" ; 
updateSobject.pba__SystemIsCancelled__c = true; 

result = sforce.connection.update([updateSobject]); 
if (result[0].getBoolean("success")) { 
location.reload(true); 
} else { 
alert("{!$Label.pba__Generic_ErrorOccured}: " + result[0].errors.message); 
} 

} catch(e) { 
alert("{!$Label.pba__Generic_ErrorOccured}: " + e); 
} 

} 
}

}

Kindly mark the solution as the answer if it works
Veenesh
Bogdan PascuBogdan Pascu
Hi Veenesch

I have tried with your code and I still get the folowing error: 

A problem with the OnClick JavaScript for this button or link was encountered:

Unexpected token {
Veenesh VikramVeenesh Vikram
Try This:
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")} 

if ({!pba__Offer__c.pba__SystemIsCancelled__c}) { 
	alert("{!$Label.pba__Offer_ErrorAlreadyCancelled}"); 
} 
else{ 
	if (ISBLANK({!pba__Offer__c.Offer_canceled_comments__c})) { 
		alert ("Please specify the reason why the Offer has been canceled!!!!"); 
	} 
	else {
		if (confirm("{!$Label.pba__Offer_ConfirmCancellation}")) { 

			var updateSobject = new sforce.SObject("pba__Offer__c"); 

			try { 

			updateSobject.Id = "{!pba__Offer__c.Id}" ; 
			updateSobject.pba__SystemIsCancelled__c = true; 

			result = sforce.connection.update([updateSobject]); 
			if (result[0].getBoolean("success")) { 
			location.reload(true); 
			} else { 
			alert("{!$Label.pba__Generic_ErrorOccured}: " + result[0].errors.message); 
			} 

			} catch(e) { 
			alert("{!$Label.pba__Generic_ErrorOccured}: " + e); 
			} 
		} 
	}

}

Veenesh
Bogdan PascuBogdan Pascu
Hi Veenesh

Now I get this error:

A problem with the OnClick JavaScript for this button or link was encountered:

ISBLANK is not defined
Veenesh VikramVeenesh Vikram
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")} 

if ({!pba__Offer__c.pba__SystemIsCancelled__c}) { 
alert("{!$Label.pba__Offer_ErrorAlreadyCancelled}"); 
} else { 
if (ISBLANK({!pba__Offer__c.Offer_canceled_comments__c})) { 
alert ("Please specify the reason why the Offer has been canceled!!!!"); 
} else {
if (confirm("{!$Label.pba__Offer_ConfirmCancellation}")) { 

var updateSobject = new sforce.SObject("pba__Offer__c"); 

try { 

updateSobject.Id = "{!pba__Offer__c.Id}" ; 
updateSobject.pba__SystemIsCancelled__c = true; 

result = sforce.connection.update([updateSobject]); 
if (result[0].getBoolean("success")) { 
location.reload(true); 
} else { 
alert("{!$Label.pba__Generic_ErrorOccured}: " + result[0].errors.message); 
} 

} catch(e) { 
alert("{!$Label.pba__Generic_ErrorOccured}: " + e); 
} 

} 
}

}

This will work, you were missing a ")" after If statement.

Veenesh
Bogdan PascuBogdan Pascu
Hi Veenesh,

I am stil getting the same error
RaidanRaidan
Hi Bogdan,

Try to replace this line:
if (ISBLANK({!pba__Offer__c.Offer_canceled_comments__c})) {
With this:
if ({!pba__Offer__c.Offer_canceled_comments__c} == '') {


 
Bogdan PascuBogdan Pascu
Hi Raida,

I have tried replacing the line of code with the new one and now I get this error:

A problem with the OnClick JavaScript for this button or link was encountered:

Unexpected token ==
RaidanRaidan
Sorry, I missed the ''
if ('{!pba__Offer__c.Offer_canceled_comments__c}' == '') {

 
This was selected as the best answer
Bogdan PascuBogdan Pascu
Hi Raida,

Many thanks, it is working perfectly. 
RaidanRaidan
Hi Bogdan,

Please mark the answer so others can also benefit from that. Thanks!