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
RajeevlsHydRajeevlsHyd 

Populate value on the VF page

I want to populate Manager's Name for the user selected in a lookup field in VF page ..

When user select EmpName -  Lookup field to user on VF apge,

I want to populate its corresponding manager's name..

 

Kindly suggest

 

 

VF page :

 

<apex:column headerValue="QC/DM Name">
<apex:inputField value="{!obj.dsObj.EmpName}" rendered="{!NOT(obj.isSummaryRecord) && NOT(obj.isFirstRecord)}"/>
<apex:outputLabel value="" style="text-align:right; font-weight: bold;" rendered="{!obj.isSummaryRecord}"/>
<apex:OutputField value="{!obj.dsObj.EmpName}" rendered="{!NOT(obj.isSummaryRecord)&& (obj.isFirstRecord)}"/>
<apex:actionsupport event="onchange" action="{!SelectManager}" rerender="!obj.isSummaryRecord, mgrName" status="waitingStatus"/>
<apex:param name="UsrId" value="{!obj.dsObj.EmpName}" assignTo="{!UsrId}"/>
</apex:column>

 

<apex:column headerValue="Manager Name" id="mgrName">
<apex:OutputField value="{!obj.dsObj.Manager__c}" rendered="{!NOT(obj.isSummaryRecord)}"/>
</apex:column>

 

 

Controller Class :

 

public PageReference SelectManager()
{
String UsrId;
String UsrName ;
User usr = [Select Id, Name , Reports_To__c from User where IsActive = true and Id =: UsrId Limit 1];
UsrName = usr.Reports_To__c ;
return Null;
}

 

 

 

GlynAGlynA

I can't be sure this will work without seeing all of the code, but this should be an improvement:

 

VisualForce page:

<apex:column headerValue="QC/DM Name">
    <apex:inputField value="{!obj.dsObj.EmpName}" rendered="{!NOT(obj.isSummaryRecord)&&NOT(obj.isFirstRecord)}">
        <apex:actionSupport event="onchange" action="{!SelectManager}" rerender="output,mgrName">
            <apex:param name="UsrName" value="{!obj.dsObj.EmpName}" assignTo="{!UsrName}"/>
        </apex:actionSupport>
    </apex:inputField>
    <apex:outputLabel value="" style="text-align:right; font-weight: bold;" rendered="{!obj.isSummaryRecord}"/>
    <apex:outputField value="{!obj.dsObj.EmpName}" rendered="{!NOT(obj.isSummaryRecord)&&(obj.isFirstRecord)}" id="output"/>
</apex:column>

<apex:column headerValue="Manager Name" id="mgrName">
    <apex:outputField value="{!obj.dsObj.Manager__c}" rendered="{!NOT(obj.isSummaryRecord)}"/>
</apex:column>

Controller:

public String UsrName { get; set; }

public PageReference SelectManager()
{
    User usr = [Select Id, Name , Reports_To__c from User where IsActive = true and Name = :UsrName Limit 1][0];
    obj.dsObj.Manager__c = usr.Reports_To__c;
    return null;
}

 

If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!

 

-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator