+ Start a Discussion
earlbarbyearlbarby 

Updating one field based on the value of another in a new object

My organization has two custom objects, Projects and Time Entries. Projects are specific work items which are associated with an account. Time entries record workers' time spent for billing purposes and include both the account and the project. I am trying to write a VF page which allows the user to create new time entries. Once they enter an account (a lookup field), the projects select list should populate with the all the projects for that account. I think the problem is that account is not actually saved yet when I rerender the project dropdown list so the parameter I use to select the projects is null and the query returns nothing. Is there a way for the controller extension to read the value that is physically in the account box on screen, not the value that is currently stored in the associated field? Am I totally missing something simple here? Thanks in advance.

Code:
<apex:page standardcontroller="Time__c" extensions="timeExtension">

   <apex:form>
   
    <apex:pageBlock title="Time Entry Edit" mode="edit">

        <apex:pageblockbuttons >
            <apex:commandButton action="{!save}" value="Save"/>
            <apex:commandButton action="{!cancel}" value="Cancel"/>
        </apex:pageblockbuttons>
                 
        <apex:pageblocksection title="Information" columns="2">
        
            <apex:inputField required="true" value="{!Time__c.Duration__c}"/>
            <apex:inputField required="true" value="{!Time__c.Date__c}"/> 
            <apex:inputField required="true" value="{!Time__c.Service__c}"/>
            <apex:inputField value="{!Time__c.Case__c}"/> 
            <apex:inputField value="{!Time__c.Billable__c}"/>  
            
            <apex:inputField required="true" value="{!Time__c.Account__c}" id="acctBox">
            <apex:actionSupport event="onblur" rerender="Projects" status="projSelStatus"/> 
            </apex:inputField>
            
            <apex:inputField value="{!Time__c.Reason__c}"/>     
            
            <apex:outputpanel id="Projects">

                <b><apex:outputLabel value="Project" for="chooseProject"/></b>
                  
                <apex:selectList id="chooseProject" size="1" value="{!Time__c.Project__c}">
                    <apex:selectOptions value="{!ProjectArray}"/>
                </apex:selectList>
                
                <apex:actionStatus id="projSelStatus" startText="(...)" />

            </apex:outputpanel> 
            
            <apex:inputField value="{!Time__c.Export_Batch__c}"/>   
            <apex:inputField value="{!Time__c.Name}"/>   
            
        </apex:pageblocksection>
        
         <apex:pageblocksection title="Description" columns="1">
            <apex:pageblockSectionItem >
                <apex:outputLabel value="Description" for="desc"/>
                <apex:inputtextarea id="desc" required="true" cols="80" rows="4" value="{!Time__c.Description__c}"/> 
            </apex:pageblockSectionItem>
        </apex:pageblocksection>
        
        <apex:pageblocksection title="System Information" columns="1" >
            <apex:outputField value="{!Time__c.OwnerID}"/>
        </apex:pageblocksection>
       
    </apex:pageBlock> 

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


public class timeExtension { private Time__c timeEntry; List<SelectOption> ProjList = null; public List<SelectOption> getProjectArray() { ProjList = new List<SelectOption>(); SFDC_Project__c[] p; Projlist.add(new selectoption('',''));
p = [select id, SFDC_Project_Name__c, account__c from SFDC_Project__c where account__c = :timeEntry.Account__c]; if (p.size() > 0) { for(integer i = 0; i <= p.size() - 1; i++){ projlist.add(new selectoption(p[i].ID, p[i].SFDC_Project_Name__c)); } } return ProjList; } public timeExtension(ApexPages.StandardController stdController) { this.timeEntry = (Time__c)stdController.getRecord(); } }