Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / How to dynamically dis...
Finance forum
Unanswered

How to dynamically display data in a form after selecting from a lookup

Posted on by

I'm working on a form in Dynamics 365 Finance & Operations where I need to show an additional field (StakeholderNameDisplay) after selecting a value from a dropdown (lookup) field (RoleCode). The idea is to fetch and display related data (e.g., a stakeholder’s title) without saving this data to the database; it should be for display purposes only.

Scenario
Table: I have a table (TUStakeholderRoles) with fields RoleCode, reportToPosition, and title.
Form: I want to add a display field (StakeholderNameDisplay) that will show the title of the selected stakeholder based on RoleCode.
Behavior: Once I select a RoleCode from the dropdown, the form should display the stakeholder’s title in StakeholderNameDisplay. This title should not be saved back to the table; it’s for display only.
Attempted Solutions
I’ve tried a few approaches but haven’t been able to get it to work as expected. Here’s what I’ve tried so far:

Solution 1: Display Method on Table

I added a display method directly in the table (TUStakeholderRoles) to retrieve the title based on the RoleCode.


public display str StakeholderNameDisplay()
{
    TUStakeholderRoles holderRoles;

    select firstOnly title from holderRoles
        where holderRoles.reportToPosition == this.RoleCode;

    return holderRoles ? holderRoles.title : 'NA';
}
This method works on a per-row basis, but when I try to use it on the form, it doesn’t update dynamically after the selection in the dropdown.

Solution 2: Adding the Display Method as a Form Control

I tried to add StakeholderNameDisplay as a control on the form by dragging it from the data source to the form design. However, the display method does not appear in the data source node in the form designer, so I couldn’t directly add it this way.

Solution 3: Using an Unbound Control with Modified Method on Dropdown

Since the display method didn’t show up directly, I added an unbound control (StakeholderNameDisplayControl) on the form. My plan was to update this control with the title dynamically. In the modified method of the dropdown control, I attempted to set the control’s text with the result of the display method:


public void modified()
{
    StakeholderNameDisplayControl.text(this.StakeholderNameDisplay());
    super();
}
But this approach failed because StakeholderNameDisplayControl was not found in scope within the data source’s methods, even though it’s in the form design.

Solution 4: Refreshing the Data Source to Update the Display Method

In another attempt, I used the modified method on the dropdown to refresh the data source, hoping it would trigger the display method to update dynamically.


public boolean modified()
{
    boolean ret;

    ret = super();

    // Refresh the data source to update the display method field
    yourTable_ds.refresh();

    return ret;
}

This didn’t produce the desired outcome either, as the display field still did not update dynamically.

Request
I’d appreciate any guidance on how to achieve the following:

Select a value in the RoleCode dropdown.
Automatically display the related title in a form field without saving it to the database.
Ensure the field updates dynamically each time the dropdown value changes.
Any solutions or alternative approaches would be really helpful. Thank you in advance
Categories:
  • CU06110926-0 Profile Picture
    CU06110926-0 on at
    How to dynamically display data in a form after selecting from a lookup
    thanks for your reply ,Martin
    the proplem is the display method doesn't trigger as well and i think is not related to cashing as not changed the value with modified 

        public void modified()
        {
            //StakeholderNameDisplayControl.text(this.StakeholderNameDisplay());
            // Refresh the data source to update the display method field
            TUStakeholderRoles_ds.refresh();
            super();
        }


    can i change 
    TUStakeholderRoles_ds.refresh();

    with something more specific as you mention in you reply

    tuStakeholderRoles_ds.cacheCalculateMethod(tableMethodStr(TUStakeholderRoles, stakeholderNameDisplay));

     or any related mothod


    -- and there any way to represent this value in the same drop down field without save it on database to not override to the saved id 
  • Martin Dráb Profile Picture
    Martin Dráb 229,173 Most Valuable Professional on at
    How to dynamically display data in a form after selecting from a lookup
    Using the display method on the table sounds like the best approach to me.

    It should work as you want by default, if no caching is involved. Haven't you, for example, decorated the method with SysClientCacheDataMethod attribute?

    The method makes a DB query, therefore caching it is a good idea, but then you need to explicitly recalculate the method instead of getting the cached value. Call cacheCalculateMethod() after changing RoleCode (in modified() method of the data source field). For example:
    tuStakeholderRoles_ds.cacheCalculateMethod(tableMethodStr(TUStakeholderRoles, stakeholderNameDisplay));
     
    (Moved from Dynamics AX forum.)

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,867 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,173 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans