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
gmc74gmc74 

Conditional Button - or using an If statement

Hi Everyone,

I have a button on a custom object that is used to track Bugs.  When the button is clicked, it should re-open a closed bug, but I don't want people to be able to click it on a bug that isn't closed.

Any thoughts?

Here is the S-Control as it stands now -


Code:
<html>
<head>
<title></title>
<script>

var newURL2 = 'https://na2.salesforce.com/{!SFDC_Bug__c.Id}/a—retURL=%2F{!SFDC_Bug__c.Id}&newOwn_lkid={!$User.Id}&save=1';
window.location.href = (newURL2);


var newURL =
'https://na2.salesforce.com/{!SFDC_Bug__c.Id}/e–retURL=%2F{!SFDC_Bug__c.Id}&CF00N40000001M1ey=&00N40000001Uh3v=--None--&CF00N40000001M1Zh=&00N40000001M1wP=&00N40000001Uh3h=&save=0';
window.parent.location.replace(newURL);


</script>
</head>

The first URL changes the ownership to the person who clicked the button, and the second one blanks out a number of fields that I want them to fill back in.

I tried to add an if statement that basically states, if the status = closed (using the IsPickVal command) then open the URL, if not, then open a different URL.  but I am getting tons of errors saying I am missing )

Here is that code

Code:
<html>
<head>
<title></title>
<script>

var newURL2 = 'https://na2.salesforce.com/{!SFDC_Bug__c.Id}/a—retURL=%2F{!SFDC_Bug__c.Id}&newOwn_lkid={!$User.Id}&save=1';

var newURL =
'https://na2.salesforce.com/{!SFDC_Bug__c.Id}/e–retURL=%2F{!SFDC_Bug__c.Id}&CF00N40000001M1ey=&00N40000001Uh3v=--None--&CF00N40000001M1Zh=&00N40000001M1wP=&00N40000001Uh3h=&save=0';

{!IF(  ISPICKVAL(SFDC_Bug__c.SFDC_Status__c, 'Closed - 2nd Level') ,window.parent.location.replace(newURL); , 'https://na2.salesforce.com/{!SFDC_Bug__c.Id})}


</script>
</head>

 Any ideas?

Ideally I would like the button to not display at all if the criteria aren't met, but if that isn't possible, then the next best thing is to have it perform a separate function.

Thanks

Grant

 

gmc74gmc74
Does no one use these, or want to use something like this?  Or does no one know how to do it?
MarkSilberMarkSilber

Unfortunately you can't make buttons dynamically come and go without a little creative workaround.

One option is to create 2 buttons and then use Record Types to drive different page layouts based on the "state" of the bug. For example, if it's open, display the "Open Bug" page layout with the first button. If it's closed, display a different page layout with the 2nd button (same name so the user can't tell it's 2 different buttons). Workflow could handle flipping the Record Type -- we do this all the time with different objects.

The 2nd option is to create a formula field that displays a button as an image. You can use imbedded IF statements to control which button image is displayed based on the state of the record.

You should also remove the "na2.salesforce..." from the start of URLs. With the URL hardcoded, you couldn't run this in your sandbox. You only need the URL from the "/" forward.

Code:
'https://na2.salesforce.com/{!SFDC_Bug__c.Id}/a—retURL=%2F{!SFDC_Bug__c.Id}&newOwn_lkid={!$User.Id}&save=1';
window.location.href = (newURL2);

Should be: /{!SFDC_Bug__c.Id}/a—retURL=%2F{!SFDC_Bug__c.Id}&newOwn_lkid={!$User.Id}&save=1';
window.location.href = (newURL2);


 
Hope that helps.

Mark