When a user modifies the Worker field in a dialog form, then the Worker Name should be auto-populated in another dialog field within the same dialog form.
High level resolution steps
- Write Common Method in Dialog Class: In the dialog class, write a common method, uses the buffer from control to update the Worker Name field.
- Retrieve Control of Worker Field: In the dialog() method, get the control of the Worker field that the user wants to modify.
- Register Override Method: Add registerOverrideMethod to call the custom method in the same control.
Detailed resolution steps
Step 1: In the dialog class, write a common method that uses the buffer from control to update the Worker Name field.
Explanation: This code handling modifications “modifyWorkerId” This ensures that when a Worker ID is entered or modified, the corresponding Worker Name is automatically populated in the dialog.
public boolean modifyWorkerId(FormStringControl _control)
{
boolean ret = _control.modified();
if (ret)
{
if (_control.valueStr())
{
HcmWorker hcmWorker =
HcmWorker::findByPersonnelNumber(_control.valueStr());
workerName.value(hcmWorker.name());
}
else
{
workerName.value("");
}
}
return ret;
}
Step 2: In the dialog() method, get control of the Worker field that the user wants to modify. Add registerOverrideMethod to call the custom method in the same control.
DialogRunbase dialog;
DialogField worker, workerName;
FormBuildStringControl workerControl;
HcmPersonnelNumberId workerValues;
Object dialog()
{
dialog = super();
worker = dialog.addField(extendedTypeStr(HcmPersonnelNumberId));
workerName = dialog.addField(extendedTypeStr(Name));
workerControl = worker.control();
workerControl.registerOverrideMethod(methodstr(FormStringControl,
modified),methodstr(SCCRunbaseDialogClass, modifyWorkerId), this);
return dialog;
}
Output
When user clicks the Worker field, worker name is auto populated.
Dynamics 365 for Operations Technical Consultant | Passionate about coding, customizations, and workflow optimization