+ Start a Discussion
chiranjeevitgchiranjeevitg 

Not able to store the controller string value in Javascript variable.

Hi,

 

I'm developing a visualforce page, in that i want to pass the string url from controller to page and then i want to store the output value in Javascript variable. Here i'm able to pass the value from controller to visaulforce pag, but i'm not able to store the output value to javascript variable. When i pass the javascript variable in alert it shows undefined. Can any one please help me to solve this issue.

 

 

visualforce Code

<apex:page standardcontroller="quote" extensions="ApprovalCheck" showHeader="false" sidebar="false">
<apex:form id='form1'>

    
     <apex:actionFunction name="getAPIParams" id="getAPIParams" action="{!temp}" reRender="theForm" >
         <apex:param name="sessionId" assignTo="{!apiSessionId}" value="{!$Api.Session_ID}" />
         <apex:param name="serverURL" assignTo="{!apiServerURL}" value="{!$Api.Partner_Server_URL_140}" />
     </apex:actionFunction>
    
    <apex:actionFunction name="popUp" id="popUp" action="{!temp}" reRender="theForm" >
    </apex:actionFunction>
   <apex:outputText id="Msg" value="{!Msg}"></apex:outputText>
  <!-- <apex:outputLink value="{!Msg}">Click Here</apex:outputLink> -->
    
    <script type="text/javascript">
     window.onload = function() { getAPIParams();}
        function openWindow()
        {
            var url = document.getElementById("{!$Component.form1.Msg}").value;
            alert(url);
            myref = window.open(url);
            
        }
    </script>
        <!--<apex:commandButton value="Save" action="{!save}" title="Clone"/>-->
        
        
        <apex:commandButton value="Product With Incentives" action="{!temp}"/>
        <apex:commandButton value="Click Here" onclick="openWindow()"/>
   

</apex:form>
</apex:page>

 

Apex Class

public class ApprovalCheck {
    
    public ApprovalCheck(ApexPages.StandardController controller) {
     
    }
    public static string url{get; set;}
    public static string Msg{get; set;}
    public String apiSessionId {get;set;} 
    public String apiServerURL {get;set;} 

    public void temp()
    {
        String Record_Id = ApexPages.CurrentPage().getParameters().get('id');
        System.debug('apiSessionId: ' + apiSessionId); 
        System.debug('apiServerURL: ' + apiServerURL); 

        List<Quote> AllQuotes = [SELECT Id, Name, OpportunityId, ContactId, ExpirationDate, Status, Email, Phone, Fax, 
                             IsSyncing, Description, Primary_Secondary__c, TotalPrice__c, Tax, ShippingHandling, BillingName, 
                            BillingStreet, BillingState, BillingPostalCode, BillingCity, BillingCountry,
                             ShippingName, ShippingStreet, ShippingState, ShippingPostalCode, ShippingCity,
                             ShippingCountry, (Select Id, TargetObjectId, StepStatus
                             From ProcessSteps) FROM Quote WHERE Id =: Record_Id];
    
        List<Quote> NewVals = new List<Quote>();
                              
        for(Quote q1 :AllQuotes)
        {
            for(ProcessInstanceHistory p1:q1.ProcessSteps)
            {
                if(p1.StepStatus == 'Approved')
                {
                    //Msg = 'https://www.appextremes.com/apps/Conga/PointMerge.aspx?SessionId={!API.Session_ID}&ServerUrl={!API.Partner_Server_URL_80}&Id='+ Record_Id+'&TemplateId=01HS000000005Ms&ds4=1&DefaultLocal=0&fp0=1&ds5=1&ds6=1&DefaultPDF=1';
                    Msg = 'https://www.xxxxxxx.com/apps/xxxxx/PointMerge.aspx?SessionId='+ apiSessionId +'&ServerUrl='+ apiServerURL +'&Id='+ Record_Id+'&TemplateId=01HS000000005O0&ds4=1&DefaultLocal=0&fp0=1&ds5=1&ds6=1&DefaultPDF=1';
                }
                else if(p1.StepStatus == 'Pending')
                {
                    Msg = 'Not Approved';
                }
           }
        }
        
    }
}

 

Thank you.

 

WesNolte__cWesNolte__c

Hi

 

Your call to $Component needs to be at the same level in the DOM as the element it's referencing. Please see here for details: http://th3silverlining.com/2009/06/17/visualforce-component-ids-javascript/

 

Wes