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
Shannon Andreas 21Shannon Andreas 21 

Javascript button help

I need help. Not very good at javascript...yet.

I need a button that will reference a URL that is located within the Account record. Sounds simple right? Maybe it is, but it complicates things for me because of the way that it is constructed.

We have two fields on the record: RRID# and RRID URL. The RRID# is a specific number that we need to assign through dataloader (e.g. 12345). The RRID URL is a complex formula field that refers tot eh RRID#:

"https://prod.vendor.com/Report/Index/?rrid="& text(RRID__c) &"&hash=" &
text(CASE(month(today()), 1, 49*1, 2, 48*2, 3, 50*3, 4, 57*4, 5, 50*5, 6, 48*6, 7, 49*7, 8, 53*8, 9, 80*9, 10, 101*10, 11, 110*11, 12, 115*12, 0) + DAY(today()) + mod( RRID__c , DAY(today())))
&"&partnerkey=1234567PenYs"

So basically, the URL would end up looking something like this:

https://prod.vendor.com/Report/Index/?rrid=15&hash=93&partnerkey=1234567PenYs (https://prod.vendor.com/Report/Index/?rrid=15&hash=93&partnerkey=1234567PenYs)

We want users to be able to click a button as opposed to the link in the body of the record. How would I accomplish this?

Thanks in advance for your help!

Shannon
Best Answer chosen by Shannon Andreas 21
Morgan MarcheseMorgan Marchese
Hey Shannon,

Should be a pretty simple JavaScript button, try this:
 
{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")} 
var url = "{!Your_Object__c.Your_URL_Field__c}"; 

if(url == null || url == ''){ 
alert('Error: There is no Valid URL on this Record'); 
} 

else{ 
window.location.href = url;
}

 

All Answers

Shannon Andreas 21Shannon Andreas 21
Also, if anyone knows how to color code the button. I would love to do that as well with this script!
Morgan MarcheseMorgan Marchese
Hey Shannon,

Should be a pretty simple JavaScript button, try this:
 
{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")} 
var url = "{!Your_Object__c.Your_URL_Field__c}"; 

if(url == null || url == ''){ 
alert('Error: There is no Valid URL on this Record'); 
} 

else{ 
window.location.href = url;
}

 
This was selected as the best answer