0

found error after clicking button'Genrate invoice'

Error:: Uncaught SyntaxError: Unexpected token **

how to resolve this??

visual force page::

<apex:page standardController="Payment__c" extensions="Search" sidebar="false" showHeader="false"  id="pageid" docType="html-5.0">

<apex:commandButton value="Generate Invoice" onclick="GenerateInvoicePay()"/>
                    <apex:actionFunction name="GenerateInvoicePay" action="{!GenerateInvoice}" oncomplete="openConga('{!Payment_Id}');" reRender="pageid"/>

<Script Language="JavaScript"> 
var stringvalue='{!Payment_Id}';
             function openConga(stringvalue) 
             { 
             GenerateInvoicePay();

                alert('payment Id2');

                window.location.href = '/apex/APXTConga4__Conga_Composer?SolMgr=1&'+
                                       'id='+{!Payment_Id}'&'+
                                        'serverUrl={!$API.Partner_Server_URL_370}';
               } 

  </Script> 

controller::

      public Id Payment_Id {get;private set;}
            public Id  PaymId{get; set;}

            public PageReference GenerateInvoice() 
        {
        selectedEsr = new List<Payment__c>();
        for(wrappayment wp : paymentList)
            {
                if(wp.selected == true) 
                {

               Payment_Id=wp.pay.id;
                system.debug('Payment_Idline517'+Payment_Id);
                payid=Payment_Id;
                 system.debug('payidline520'+payid);

    }
    }

    return null;
        }
0

You are getting this error because you are not constructing the URL properly. You need to make few changes for this to work.

  • You are calling the actionFunction again from javascript method which takes your code into recursion which is not needed.
  • There is no need of actionFunction as you can call your javascript method from oncomplete event of commandButton.

This is the working code, see if it can help you

<apex:page standardController="Payment__c" extensions="Search" sidebar="false" showHeader="false"  id="pageid" docType="html-5.0">
    <apex:form >
        <apex:commandButton value="Generate Invoice" action="{!GenerateInvoice}" oncomplete="openConga('{!Payment_Id}');" reRender="pageid"/>
        <script Language="JavaScript"> 
            //var stringvalue='{!Payment_Id}';
            function openConga(valueFromParam) { 
                //GenerateInvoicePay();  //comment this as you don't need it.
                alert(valueFromParam);
                window.location.href = "/apex/APXTConga4__Conga_Composer?SolMgr=1&"+
                "id="+ valueFromParam + "&serverUrl={!$API.Partner_Server_URL_370}";
            } 
        </script>
    </apex:form>
</apex:page>
  • @@Vijay Ganji..As per your suggestion i modified but issue occured issue::1) after click on the button , conga page is not coming even alert is also not showing. please reply as soon as possible – Juhi.L Jan 30 at 8:50
  • Updated the answer. Please check now – Vijay Ganji Jan 30 at 8:52
  • @@ Vijay Ganji Still facing same issue – Juhi.L Jan 30 at 8:58
  • @@Tushar Sharma,@@Vijay Ganji, how to call Conga Page for selected ID? please help me.. – Juhi.L Jan 30 at 9:20
  • Updated the answer. Please check now, also make sure that the development mode is switched off before testing this. – Vijay Ganji Jan 30 at 9:24
0

Your code is calling recursive. You need to comment the second actionfunction calling from your JavaScript method.

<apex:page standardController="Payment__c" extensions="Search" sidebar="false" showHeader="false"  id="pageid" docType="html-5.0">
<apex:commandButton value="Generate Invoice" onclick="GenerateInvoicePay()"/>
<apex:actionFunction name="GenerateInvoicePay" action="{!GenerateInvoice}" oncomplete="openConga('{!Payment_Id}');" reRender="pageid"/>
<Script Language="JavaScript"> 
    var stringvalue='{!Payment_Id}';
                 function openConga(stringvalue) 
                 { 
                 //GenerateInvoicePay();

                    alert('payment Id2');

                    window.location.href = '/apex/APXTConga4__Conga_Composer?SolMgr=1&'+
                                           'id='+{!Payment_Id}'&'+
                                            'serverUrl={!$API.Partner_Server_URL_370}';
                   } 


</Script>

So your command button wil call the actionfunction which in place will call the JS method. But in existing code you need to add rerender="none" in your command button. But if you want you can remove the actionFunction here.

This code will also work and will give you same results.

<apex:page standardController="Payment__c" extensions="Search" sidebar="false" showHeader="false"  id="pageid" docType="html-5.0">
<apex:commandButton value="Generate Invoice" action="{!GenerateInvoice}" oncomplete="openConga('{!Payment_Id}');" reRender="pageid"/>
<Script Language="JavaScript"> 
    var stringvalue='{!Payment_Id}';
                 function openConga(stringvalue) 
                 { 
                 //GenerateInvoicePay();  //comment this as you don't need it.

                    alert('payment Id2');

                    window.location.href = '/apex/APXTConga4__Conga_Composer?SolMgr=1&'+
                                           'id='+{!Payment_Id}'&'+
                                            'serverUrl={!$API.Partner_Server_URL_370}';
                   } 


</Script>
  • But ID is not calling inside the conga URL window.location.href = '/apex/APXTConga4__Conga_Composer?SolMgr=1&'+ 'id='+{!Payment_Id}'&'+ 'serverUrl={!$API.Partner_Server_URL_370}'; In conga page error is coming 'The id parameter is missing.' please reply as soon as possible. – Juhi.L Jan 30 at 7:31
  • Can you try to replace {!Payment_Id}' with the stringvalue parameter. – Tushar Sharma Jan 30 at 7:32
  • @@ Tushar Sharma .. I added this code::window.location.href = '/apex/APXTConga4__Conga_Composer?SolMgr=1&'+ 'id=stringvalue&'+ 'serverUrl={!$API.Partner_Server_URL_370}'; coming error:: Not authorized. The stringvalue parameter ID is not valid. Ensure that the parameter ID is 15 to 18 alpha-numeric characters and does not include spaces. in conga page – Juhi.L Jan 30 at 7:44
  • @Juhi.L Can you try window.location.href = '/apex/APXTConga4__Conga_Composer?SolMgr=1&'+ 'id='+stringvalue+'&'+ 'serverUrl={!$API.Partner_Server_URL_370}' – Tushar Sharma Jan 30 at 8:30
  • @@Tushar Sharma,Vijay Ganji on visualforce page for "invoice" object there is a button genrate pdf. After selecting the record and After Clicking on the genrate pdf button,directly the pdf should be downloaded and email should be sent. In the backend I have created a Conga button on the "invoice " object and add template id there in the conga button. Now my requirement is "When the we selects the record from visualforce page and click on the button Then a invoice pdf is generated and stored in the system ready to download and send to the customer via email"help me.. – Juhi.L Jan 31 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.