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
gthyaergthyaer 

Help with OnClick JavaScript Button

I am trying to build a javascript button, which when clicked will perform a different action dependant upon the content of a custom field in Salesforce. It seems to be defaulting to the first "IF" statement regardless of what is entered into the field, unless the field is blank. If the field is blank I receive an error message, not the "ELSE" statement.

 

Thank for looking at this. I have already posted in the Saleforce forums and will hopefully get a reply soon. This is my first attempt with Javascript and I am not certain I hit all my marks.


I have discovered by changing the "ELSE IFs" to "IF" will default to the last entry, not the first. Below is the code. Thank you in advance for your assistance.

if ({!Lead.Description}= "onlinereg")

{
window.location = "/lead/leadconvert.jsp?IsReminderSet_fu=0&nooppti=1&id={!Lead.Id}&RetURL=/{!Lead.Id}";
}

else if ({!Lead.Description}= "onlineCEUreg")

{
window.location = "/00T/e?tsk1=Certifications%20User&tsk2={!Lead.Name}&RetURL={!Lead.Id}&email=1&tsk2_mlktp=00Q&IsReminderSet=0&tsk5=CEU%20Order";
}

else if ({!Lead.Description}= "renewbyexam")

{
window.location = "/00T/e?tsk1=Certifications%20User&tsk2={!Lead.Name}&RetURL={!Lead.Id}&email=1&tsk2_mlktp=00Q&IsReminderSet=0&tsk5=Renewal%20by%20Exam";
}

else if ({!Lead.Description}= "renewbyCEU")

{
window.location = "/00T/e?tsk1=Certifications%20User&tsk2={!Lead.Name}&RetURL={!Lead.Id}&email=1&tsk2_mlktp=00Q&IsReminderSet=0&tsk5=Renewal by CEU";
}

else

{
alert("This lead can not be marked as paid.");
}

Best Answer chosen by Admin (Salesforce Developers) 
Prafull G.Prafull G.

Few tweeks required... highlighted in red

 

if ("{!Lead.Description}" == "onlinereg")

{
window.location = "/lead/leadconvert.jsp?IsReminderSet_fu=0&nooppti=1&id={!Lead.Id}&RetURL=/{!Lead.Id}";
}

else if ("{!Lead.Description}" == "onlineCEUreg")

{
window.location = "/00T/e?tsk1=Certifications%20User&tsk2={!Lead.Name}&RetURL={!Lead.Id}&email=1&tsk2_mlktp=00Q&IsReminderSet=0&tsk5=CEU%20Order";
}

else if ("{!Lead.Description}" == "renewbyexam")

{
window.location = "/00T/e?tsk1=Certifications%20User&tsk2={!Lead.Name}&RetURL={!Lead.Id}&email=1&tsk2_mlktp=00Q&IsReminderSet=0&tsk5=Renewal%20by%20Exam";
}

else if ("{!Lead.Description}" == "renewbyCEU")

{
window.location = "/00T/e?tsk1=Certifications%20User&tsk2={!Lead.Name}&RetURL={!Lead.Id}&email=1&tsk2_mlktp=00Q&IsReminderSet=0&tsk5=Renewal by CEU";
}

else

{
alert("This lead can not be marked as paid.");
}

All Answers

Prafull G.Prafull G.

Few tweeks required... highlighted in red

 

if ("{!Lead.Description}" == "onlinereg")

{
window.location = "/lead/leadconvert.jsp?IsReminderSet_fu=0&nooppti=1&id={!Lead.Id}&RetURL=/{!Lead.Id}";
}

else if ("{!Lead.Description}" == "onlineCEUreg")

{
window.location = "/00T/e?tsk1=Certifications%20User&tsk2={!Lead.Name}&RetURL={!Lead.Id}&email=1&tsk2_mlktp=00Q&IsReminderSet=0&tsk5=CEU%20Order";
}

else if ("{!Lead.Description}" == "renewbyexam")

{
window.location = "/00T/e?tsk1=Certifications%20User&tsk2={!Lead.Name}&RetURL={!Lead.Id}&email=1&tsk2_mlktp=00Q&IsReminderSet=0&tsk5=Renewal%20by%20Exam";
}

else if ("{!Lead.Description}" == "renewbyCEU")

{
window.location = "/00T/e?tsk1=Certifications%20User&tsk2={!Lead.Name}&RetURL={!Lead.Id}&email=1&tsk2_mlktp=00Q&IsReminderSet=0&tsk5=Renewal by CEU";
}

else

{
alert("This lead can not be marked as paid.");
}

This was selected as the best answer
gthyaergthyaer

That's it! Thank you for the help!