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
Олег СавинковОлег Савинков 

controller method not calling from actionfanction

Help, please!
I have VF page
<apex:page standardController="CallReportHosp__c" extensions="CtrlCallHospInsert" id="CallsHospInsert">
 <apex:form id="myForm">
  

<script>
                        function getV() {

                            var AccValue = document.getElementById("CallsHospInsert:myForm:pblock:pBS:pBSI:organisation").value;
                            document.getElementById("CallsHospInsert:myForm:pblock:theHiddenInput").value=AccValue;
                            console.log('getv '+AccValue);
                            myFun();        
                                                                       
                        }
                    </script>

<script>     
 function openLookup(BaseUrl,width,modified,searchstr)
        {
           var receivedUrl=BaseUrl;
           var receivedwidth=width;
           var receivedmodified=modified;
           var receivedsearchstr=searchstr;
           var lookuptype=receivedUrl.substr(receivedUrl.length-3,3);
           if(receivedmodified=='1')
           {
               BaseUrl=BaseUrl+searchstr;
           }
           var urlArr=BaseUrl.split("&");
               //----If you are using this in inline editing then it would be var NxtSpltArr=urlArr[0].split("="); -----------
               var NxtSpltArr=urlArr[1].split("=");
               var txtfrmarr=NxtSpltArr[1];
           if(lookuptype=='001')
           {
             
           if(txtfrmarr.indexOf('organisation')> -1)
               {

                   BaseUrl="/apex/AccountsListforHosp?context=pharma_chain&list=noList&txt="+txtfrmarr;
                   BaseUrl=BaseUrl + "&frm=" + escapeUTF("{!$Component.myForm}");
                   BaseUrl=BaseUrl + "&lksearch=" + searchstr;
               }
           
               
           }
            if(lookuptype=='003')
           {
              
           
           if(txtfrmarr.indexOf('contact')> -1)
               {   
                   var orgid = document.getElementById("CallsHospInsert:myForm:pblock:theHiddenInput").value;
                   BaseUrl="/apex/ContactsListforHosp?context=pharma_chain&list=noList&org="+orgid+"&txt="+txtfrmarr;
                   BaseUrl=BaseUrl + "&frm=" + escapeUTF("{!$Component.myForm}");
                   BaseUrl=BaseUrl + "&lksearch=" + searchstr;
               }               
           }
           openPopup(BaseUrl,"lookup",950,480,"width=1420,height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no",true);   

        }
</script>

            
<apex:actionfunction name="myFun" action="{!SelectServiceIns}" onComplete="alert('After apex method') ;">
<!--  <apex:param name="AccIns" value="" assignTo="{!AccIns}"/>-->
  
</apex:actionFunction>            
            
            
        <apex:pageBlock mode="edit" id="pblock" >
            <apex:pageMessages id="message" />
            <apex:pageBlockButtons location="top">                                
                <apex:actionStatus id="mySaveStatus1">
                <apex:facet name="stop">
                <apex:commandButton value="Save" action="{!save}" rerender="pblock" status="mySaveStatus1"/>
                </apex:facet>
                <apex:facet name="start">
                <apex:commandButton value="Save" status="mySaveStatus1" disabled="true"/>
                </apex:facet>
                </apex:actionStatus>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            
   <apex:inputHidden value="{!AccIns}" id="theHiddenInput"/>    
   <apex:actionSupport action="{!SelectServiceIns}"/>     

             
<!--            <apex:outputPanel rendered="{!IF($CurrentPage.parameters.theType = 'app', false, true)}" >-->
            <apex:pageBlockSection columns="2" id="pBS">
                <apex:pageBlockSectionItem id="pBSI">                
                    <apex:outputLabel value="Organisation" for="organisation"/>
                    <apex:inputfield value="{!rep.AccountID__c}" id="organisation" required="true" >
                        <apex:actionSupport event="onchange" action="{!SelectServiceIns}" reRender="contactPanel" status="status" oncomplete="getV(); return true;"  />
                    </apex:inputfield>
                </apex:pageBlockSectionItem>
                
                
                
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Date" for="datetime"/>
                    <apex:inputfield value="{!rep.Date__c}" id="theDate"/>
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Address"/>
                    <apex:outputText value="{!rep.AccountID__r.BillingCity},{!rep.AccountID__r.BillingStreet}" id="address" >
                    </apex:outputText>
and i have controller:
public class CtrlCallHospInsert {


public CallReportHosp__c rep {get; set;}

public String AccIns{get;set;}

private Account rep2;



private ApexPages.StandardController controller { get; set; }

    public CtrlCallHospInsert(ApexPages.StandardController controller) {
         this.controller = controller; 
         this.rep = new CallReportHosp__c();
         this.rep.AccountID__c=NULL;
         this.rep.ContactID__c=NULL;
         this.rep.Duration__c='30 min';
         AccIns='';
    }



public PageReference save(){
        
        try {
            insert rep;
        }catch (Exception e){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '"Something went wrong !"'));
        }
        PageReference pageRef = Page.CallsHospList;
        pageRef.setRedirect(true);
        return pageRef;
    }
    
    
public PageReference SelectServiceIns(){ 
System.debug('select ');
 System.debug('acc = '+AccIns);
 this.rep.AccountID__c=AccIns;
 this.rep.put('AccountID__c',AccIns);
 System.debug('new value= '+this.rep.get('AccountID__c'));
 System.debug('accvalue= '+AccIns);
 rep2=[Select id, BillingCity, BillingStreet  FROM Account where id=:AccIns];
 this.rep.AccountID__r.BillingCity=rep2.BillingCity;
 this.rep.AccountID__r.BillingStreet=rep2.BillingStreet;  
// this.Acc = rep2.Id;
 this.rep.AccountID__c=AccIns;
 this.rep.put('AccountID__c',AccIns);
 System.debug('new value= '+this.rep.get('AccountID__c'));
 System.debug('accvalue= '+AccIns);
return null;
}

    
 public PageReference cancel() {
        PageReference pageRef = Page.CallsHospList;
        pageRef.setRedirect(true);
        return pageRef;        
    }
    
}
I tried to call controller method SelectServiceIns from actionfunction. I see that function working ( console.log('getv '+AccValue) - returned true value), i see that actionfunction started ( alert('After apex method') ; - returned on page), but my method not calling!!!I can't see System.debug('select ') in system journal. And  i  Inserting new object with my lookup window so i cant't use standard controller and onchage event don't work on field AccountID__c (what's weird)

 
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi ,
Try by giving rerender in actionfunction and also write the script outside of form tag
Please refer below link which might help you in this
https://developer.salesforce.com/forums/?id=906F00000008mEHIAY

Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards