0

I need help.

I have a custom button on opportunity "Involve PreSales". I inserted in this button a javascript code. If the conditions are verified it opens vf page, if conditions aren't verified it should open alert.

<apex:page standardController="Opportunity" extensions="InvolvePreSales" action="{!Start}">

<script type = "text/javascript"> 
    window.onload=function Verify() 
{ 
if ("{!Opportunity.Demand_Activity_Stage__c}"!="Involved")  && (("{!Opportunity.Opportunity_Type__c}" == "Delivery") || ("{!Opportunity.Opportunity_Type_def__c}" == "Partner") || ("{!Opportunity.Opportunity_Type_def__c}" == "Partner Direct"))
window.location.href = "/apex/Involve_PreSales?Id={!Opportunity.Id}";
//else if ("{!(Opportunity.Opportunity_Type_def__c)}" == 'Partner Direct')
//alert("You cannot involve PreSales for Partner Direct Opportunity");
else if ("{!(Opportunity.Demand_Activity_Stage__c)}" == "Involved")
alert("The PreSales has already been involved");
};
    </script>  
<apex:form >
<apex:pageMessages />
    <apex:pageBlock rendered="{!showfields}">
        <apex:pageBlockButtons rendered="{!showfields}" location="top">
            <apex:commandButton value="Involve" action="{!Involve}"/>
            <apex:commandButton value="Cancel" action="{!Cancel}"/>
        </apex:pageBlockButtons>

        <apex:pageBlockSection >
            <apex:inputField required="true" value="{!o.Number_of_Templates__c}" rendered="{!isblank(o.Number_of_Templates__c)}"/>
            <apex:inputField required="true" value="{!o.Number_of_Documents_per_Year__c}" rendered="{!isblank(o.Number_of_Documents_per_Year__c)}"/>
            <apex:inputField required="true" value="{!o.Number_of_Pages_per_Year__c}" rendered="{!isblank(o.Number_of_Pages_per_Year__c)}"/>
            <apex:inputField required="true" value="{!o.Offer_Definition_Deadline__c}" rendered="{!isblank(o.Offer_Definition_Deadline__c)}"/>

            <apex:inputField required="true" value="{!o.Document_Families__c}" rendered="{!isblank(o.Document_Families__c)}"/>
            <apex:inputField required="true" value="{!o.Peak_Period__c}" rendered="{!isblank(o.Peak_Period__c)}"/>
            <apex:inputField required="false" value="{!o.Technical_Description__c}" rendered="{!isblank(o.Technical_Description__c)}" style="width: 500px; height: 100px"/>
            <apex:inputField required="true" value="{!o.Emission_Peak_num_of_pages__c}" rendered="{!isblank(o.Emission_Peak_num_of_pages__c)}"/>

        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>

the problem is that in positive case it opens the vf page but in negative case it do a refresh of the page and doesn't display alert.

Can someone help me?

2
  • Which button do you click? Is it a custom button and can you provide the code, I see the code only for VF page
    – manjit5190
    Commented Aug 1, 2018 at 11:19
  • Hello, I created a Detail Page Button from setup - opportunities - button link and actions - content source Visualforce page. I thought when I Click the button it executes before the javascript code then if the conditions are met it opens the page if not it displays alert
    – Frank
    Commented Aug 1, 2018 at 12:55

1 Answer 1

0

There is one extra bracket in your second condition. Remove tha. Thats causing this issue.t

else if ("{!Opportunity.Demand_Activity_Stage__c}" == "Involved")
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .