function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
CyberfireCyberfire 

Javascript button override

All,

I'm attempting to override a custom button that takes a user to an internal link - what I want to do however, is check to see if certain fields are blank or not before executing the link. What would I need to do in order to make this possible?

Rule be something like this:

If {!Primary Campaign Source} = null, do not navigate to link, instead, popup an alert box which says "This campaign is blank, blah blah etc".

Any takers?
Best Answer chosen by Admin (Salesforce Developers) 
CyberfireCyberfire
Just in case anyone is interested, my developer was able to assist with this code and get it working perfectly - here it is:

Code:
if ("{!Opportunity.Campaign}" == "")
{
alert ("This is an alert.");
}
else if ("{!Opportunity.Campaign}" == "XXXXXXXXX")
{
alert("This is a different alert.");
}
else
{
window.open("https://zzzzzzz.zzzzzzzz—campaign={!Opportunity.Campaign}-
{!Opportunity.Opportunity_Number__c}&company={!Opportunity.Account}&firstname=
{!Opportunity.mappedfirstname__c}&lastname={!Opportunity.mappedlastname__c}&email=
{!Opportunity.mappedemail__c}&phone={!Opportunity.mappedphone__c}"); }

 


All Answers

shillyershillyer
You can use the AJAX Toolkit to query the desired field and based on the response redirect the user to the URL or display the alert. Here's sample code to write a simple query.
 
Hope that helps,
Sati
CyberfireCyberfire
I've looked at the sample script, but it's pretty much greek to me...
shillyershillyer

OK - this isn't a custom button, but it's simple to implement. You could create a formula field that contains a similar IF statement:

IF(  FieldName = NULL,  "ENTER ALERT MESSAGE" ,  HYPERLINK(http://www.somewhere.com, "Your URL"))

Basically this field will display a hyperlink if your desired field has a value, otherwise it'll display your alert. You could move this field to the top of the page in its own section for better user experience. You can add images to make it more effective.

Hope that helps,

Sati

CyberfireCyberfire
Just in case anyone is interested, my developer was able to assist with this code and get it working perfectly - here it is:

Code:
if ("{!Opportunity.Campaign}" == "")
{
alert ("This is an alert.");
}
else if ("{!Opportunity.Campaign}" == "XXXXXXXXX")
{
alert("This is a different alert.");
}
else
{
window.open("https://zzzzzzz.zzzzzzzz—campaign={!Opportunity.Campaign}-
{!Opportunity.Opportunity_Number__c}&company={!Opportunity.Account}&firstname=
{!Opportunity.mappedfirstname__c}&lastname={!Opportunity.mappedlastname__c}&email=
{!Opportunity.mappedemail__c}&phone={!Opportunity.mappedphone__c}"); }

 


This was selected as the best answer