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 have tried a few approaches but haven't been able to get it to work as expected. Here's what I have 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.
I would appreciate any guidance on how to achieve the following:
Any solutions or alternative approaches would be really helpful. Thank you in advance!
Display methods are usually used to enhance the information shown in a form with data that is not part of the data sources of the form, but is related to them.
Solution 1 tries to add a display method for the title
field of the TUStakeholderRoles
table. Since that table seems to already be a data source of the form, it is not necessary to use a display method. The title
field could instead be added directly from the data source to the form controls.
However, that would not cover the requirements, since this would not change the value of the title
field when the value of RoleCode
gets changed via the dropdown.
While it is not quite clear what the required functionality is, it seems to me that TUStakeholderRoles
should not be used as a data source at all. This is because TUStakeholderRoles
seems to be used as reference data for whatever is being done in the form. First, the RoleCode
is chosen, which seems to be a unique identifier for the records in TUStakeholerRoles
, thereby identifying a record to use. Then, the title
field of the identified record is to be shown in the StakeholderNameDisplay
(although despite the control name, it is not the stakeholder's name, but the title that would be shown).
Solution 2 would not work for the same reasons. However, in general, display methods can be added to a form by dragging them from the table to the form design (given that the table is a data source on the form). To drag them from the data source would require defining the display method on the data source.
Solution 3 to me seems closest to what is actually required. However, the dropdown control for RoleCode
should also be an unbound control with logic in the modified method to determine the identified TUStakeholderRoles
record and then set the StakeholderNameDisplayControl
value. Otherwise, selecting a RoleCode
would change the unique key of the record from the data source bound to the dropdown control. Usually, after record creation, the unique key fields of the record should no longer be available for changes.
Regarding the issues that form controls are not found: Each form control has a AutoDeclaration
property that when set to Yes
makes the form control available. Alternatively, the FormRun.control
method can be used to get a reference to a form control.
Solution 4 would not work for the same reasons as solutions 1 and 2.