web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

employee name and employee id lookup value selecting first value in case of duplicate names

(0) ShareShare
ReportReport
Posted on by 212

Hi Team,

I have created a custom field for Employee name. I have added a string type field with extended data type of resource view. Suppose i have 2 john cooper with different employee id still system is selecting first value only. please help. Below is my code

class ProjectResource
{
/// <summary>
///
/// </summary>
/// <param name = "_formControl"></param>
/// <param name = "_filterStr"></param>
public void lookup(FormControl _formControl, str _filterStr)
{
super(_formControl, _filterStr);
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(ResourceView), _formControl);
Query query = new Query();
QueryBuildDataSource queryBuildDataSource,queryBuildDataSource1;
QueryBuildRange queryBuildRange;

sysTableLookup.addLookupfield(fieldnum(ResourceView,ResourceId),true);
sysTableLookup.addLookupfield(fieldnum(ResourceView,Name),true);

queryBuildDataSource = query.addDataSource(tablenum(ResourceView));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}

}

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi,

    Is this the lookup for Name field or for Resource Id field?

  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    First of all, let me paste your code in the right way (you forgot to use Insert > Code), throw away unsused variables and things like that. This should be much easier to read:

    public void lookup(FormControl _formControl, str _filterStr)
    {
    	super(_formControl, _filterStr);
    	
    	SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(ResourceView), _formControl);
    	sysTableLookup.addLookupfield(fieldNum(ResourceView, ResourceId), true);
    	sysTableLookup.addLookupfield(fieldNum(ResourceView, Name), true);
    
    	Query query = new Query();
    	query.addDataSource(tableNum(ResourceView));
    	sysTableLookup.parmQuery(query);
    	sysTableLookup.performFormLookup();
    }

    You mentioned employees, but I don't see them in your code. Do you mean ResourceView.ResourceId when talking about "employee id"? What exactly do you mean by "system is selecting"?

  • Dynamics365Admin Profile Picture
    212 on at

    Hi Martin,

    Yes you are correct I am referring to Resource id. On clicking on lookup field, it shows the list of resources name and id

    Now we have Resource name - Neha Jain  Resource id 01

    and second  Resource name - Neha Jain   Resource id 02

    Even when I am clicking on Resource id 02,  01 is getting selected and getting saved on table.

    Please help on this

  • Suggested answer
    Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    I think the bug in the fact that you want to return ResourceId, but you asked to return both ResourceId and Name. This doesn't make sense and the system probably uses the latest one, i.e. Name.

    Fix if by removing the second parameter when adding Name to the lookup:

    // Old code
    sysTableLookup.addLookupfield(fieldNum(ResourceView, Name), true);
    
    // New code
    sysTableLookup.addLookupfield(fieldNum(ResourceView, Name));

  • Dynamics365Admin Profile Picture
    212 on at

    It didn't work. I want to return name with correct resource id on which i have clicked on

  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    Please tell us more about the behavior that you want to achieve, because it currently doesn't make sense to me.

    You want to return two values (ID and name), but the purpose of a lookup is selecting a single value. If your lookup is for an ID, you should return an ID. If it's for a name, you should return a name. You said you wanted to return both, but what would you do with them?

    The right approach, IMHO, is using ID, because names aren't unique. Then you can fetch the name for the selected ID.

  • Suggested answer
    Rachit Profile Picture
    4,015 User Group Leader on at

    Hi TxTxt,

    As Martin suggested, you are using a wrong approach here.

    Have a look at how same thing is modelled in standard application. Most simple example you can find is on sales table >> workersalestaker field.

    You need to add a foreign key relation in your table with HCMWorker table and store the recID of HcmWorkerTable in your table . Then in order to display the name on the form you need to add a reference group control and select the right field group or you can create a new field group.

    Hope this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 669 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 471 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 423 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans