+ Start a Discussion
John BraunJohn Braun 

Onclick javascript custom button - conditional statement that will take you to different links

Hello!,

I'm stuck on trying to create an onclick javascript custom button for the below situation:

Ex.
Opportunity Record Type: 1
Opportunity Name: A

From Opportunity “A”, a user creates a related opportunity (Opportunity B), from a related list on Opportunity A’s page layout, that uses Opportunity A’s record type (record type: 1).

Now there are two related opportunities, Opportunity A and Opportunity B.

If the user creates another opportunity (Opportunity C) using the same related list record from either Opportunity A or B, the newly created opportunity record would still be related to Opportunity A. The same would apply to any subsequent opportunities created from Opportunity A, B, or C, would all link back to Opportunity A and would be visible in Opportunity A’s related list.

So, I thought I could create a custom button that would check to see if the custom opportunity lookup field is blank, and if so, then just send the opportunity name/id to populate that lookup field on the about to be new opportunity record.

If the custom opportunity lookup field is NOT BLANK, then it would just use the value already there, which would be the original parent opportunity (opportunity A).

I've come up with the following syntax for the Onclick Javascript button, but it doesn't work:

if ('{!Opportunity.Original_Related_Opportunity2__c}' == ")
{window.location = "/006/e?
&RecordTypeID=012Z00000000Ufo
&Opportunity_lkid={!Opportunity.Id}
&accid={!Opportunity.AccountId}
&CF00NZ0000000oxZo_lkid={!Opportunity.Id}
&CF00NZ0000000oxZo={!Opportunity.Name}
&opp3='Will Auto-Populate'
&00NZ0000000ogsU= 'PDS'
&ent=Opportunity";
}
else {window.location = "/006/e?
&RecordTypeID=012Z00000000Ufo
&Opportunity_lkid={!Opportunity.Id}
&accid={!Opportunity.AccountId}
&CF00NZ0000000oxZo={!Opportunity.Original_Related_Opportunity2__c}
&opp3='Will Auto-Populate'
&00NZ0000000ogsU='PDS'
&ent=Opportunity";
}

Does anyone have any suggestions? Thanks so much for any help!!


SonamSonam (Salesforce Developers) 
Hi John,

Have you customized the Opportunity Object so as to create related Opportunites?
I would like to test this on my test ORG and wish to understand if you have created a self lookup relationship between Opportunities.