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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Suggested Answer

Adding a lookup field in a dialog using UI builder class

(1) ShareShare
ReportReport
Posted on by 2
Hi DAXers,
 
I am facing an weird issue. I am required to create a dialog where I have a drop down on a field, EDT as TMSCarrierCode, the field is present in TMSCarrier table. Based on the selection of this value, I am supposed to get value in a different field, I have created my contract class, Controller class, UI builder class and a service class.
 
my contract class is given below 
[   
    DataContractAttribute,
    SysOperationContractProcessing(classstr(CustomUIBuilder))
]
public class CustomContract
{
[
    DataMemberAttribute('CarrierCode'),
    SysOperationLabelAttribute("@TRX331"),
    SysOperationDisplayOrderAttribute('9')
]
public TMSCarrierCode parmCarrierCode(TMSCarrierCode _carrierCode = carrierCode)
{
    carrierCode = _carrierCode;
    return carrierCode;
}
}
 
And here is my UI builder class 
 
public final class CustomUIBuilder extends SysOperationAutomaticUIBuilder
{
    DialogField  carrierCodeDialogField, carrierNameDialogField;
public void postBuild()
{
    CustomContract contract;
    super();
    contract =  this.dataContractObject() as CustomContract;
    carrierCodeDialogField = this.bindInfo().getDialogField(contract,methodStr(CustomContract, parmCarrierCode));
    carrierNameDialogField = this.bindInfo().getDialogField(contract,methodStr(CustomContract, parmCarrierName));
    carrierCodeDialogField.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(CustomUIBuilder, lookupCarrier), this);
    carrierCodeDialogField.registerOverrideMethod(methodStr(FormStringControl, modified),methodStr(CustomUIBuilder, carrierCodeChanged), this);
    
}
public void carrierCodeChanged(FormStringControl _formStringControl)
{
    TMSCarrier          tmsCarrier;
    TMSName             carrierName;
    TMSCarrierCode      carrierCode = carrierCodeDialogField.value();
    tmsCarrier = TMSCarrier::find(carrierCode);
    carrierName = tmsCarrier.Name;
    carrierNameDialogField.value(carrierName);
}
public void lookupCarrier(FormStringControl _formStringControl)
{
    Query                   query = new Query();;
    QueryBuildDataSource    qbds;
    SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(TMSCarrier),_formStringControl);
    sysTableLookup.addLookupfield(fieldNum(TMSCarrier, CarrierCode));
    sysTableLookup.addLookupfield(fieldNum(TMSCarrier, Name));
    sysTableLookup.addLookupfield(fieldNum(TMSCarrier, VendorCode));
    
    qbds = query.addDataSource(tableNum(TMSCarrier));
    qbds.addRange(fieldNum(TMSCarrier,Active)).value(queryValue(NoYes::Yes));
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
 
now everything seems fine, I can even get my values from the drop down, my 2nd field also gets the values as intended. But I am getting an weird validation error. With an yellow warning sign, it tells me the data entered in the Carrier code field is not valid. I know for a fact they are correct.
 
I tried creating a new drop down for a different field, it is working fine. I am getting the error only for this specific field.
Any ideas?
Appreciate any help on this matter!
 
I have the same question (0)
  • Martin Dráb Profile Picture
    239,451 Most Valuable Professional on at
    Is it related to your code? I mean, does the problem disapper when you remove the overrides of lookup() and/or modified()? So far, I don't see any problem in your code, therefore a better isolation of the problem (and maybe finding that we're looking at a wrong place) would help.
     
    It's off-topic, but you'll get code that is shorter and easier to work with if you declare variables where needed, not on the top of the method. For example, this:
    public void carrierCodeChanged(FormStringControl _formStringControl)
    {
        TMSCarrier          tmsCarrier;
        TMSName             carrierName;
        TMSCarrierCode      carrierCode = carrierCodeDialogField.value();
        tmsCarrier = TMSCarrier::find(carrierCode);
        carrierName = tmsCarrier.Name;
        carrierNameDialogField.value(carrierName);
    }
    could be simply:
    public void carrierCodeChanged(FormStringControl _formStringControl)
    {
        TMSCarrierCode carrierCode = carrierCodeDialogField.value();
        TMSCarrier tmsCarrier = TMSCarrier::find(carrierCode);
        carrierNameDialogField.value(tmsCarrier.Name);
    }
    Moved from Integration, Dataverse, and general topics forum.
  • Suggested answer
    Navneeth Nagrajan Profile Picture
    2,613 Super User 2026 Season 1 on at
    Hi,
     
    As Martin rightly said, your code is fine, however suspect it is to do with the Name field. This is a problem that has been existing since the Ax2012 R3 days where we have the Name field and a combo field together breaking the lookup.
     
    Fix to the problem:
    Recommendation is to group the fields together CarrierCode,Name and VendorCode in a field group called TMSShippingCarrierGroup on table TMSCarrier through an extension. In this case, named the Field group as TMSShippingCarrierGroup.
     
    public void lookupCarrier(FormStringControl _formStringControl)
    {
        Query                   query = new Query();;
        QueryBuildDataSource    qbds;
       
        //SysFieldGroupLookup addition
        SysFieldGroupLookup lookup = SysFieldGroupLookup::newParameters(tableNum(TMSCarrier),_formStringControl);
        //SysFieldGroupLookup addition
       
        //SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(TMSCarrier),_formStringControl);
        //sysTableLookup.addLookupfield(fieldNum(TMSCarrier, CarrierCode));
        //sysTableLookup.addLookupfield(fieldNum(TMSCarrier, Name));
        //sysTableLookup.addLookupfield(fieldNum(TMSCarrier, VendorCode));
        
        qbds = query.addDataSource(tableNum(TMSCarrier));
        qbds.addRange(fieldNum(TMSCarrier,Active)).value(queryValue(NoYes::Yes));
       
        lookup.parmQuery(query);
        //Field Group Lookup
        lookup.parmFieldGroupNameForLookup(fieldGroupStr(TMSCarrier,TMSShippingCarrierGroup));
          
        //Assuming you have CarrierCode as your default selection id field
        lookup.parmCloseSelectFieldId(fieldnum(TMSCarrier,CarrierCode));
     
        //Field Group Lookup
        sysTableLookup.performFormLookup();
    }
     
    Hope this helps. Happy to answer questions, if any.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 130 Super User 2026 Season 1

#2
Laurens vd Tang Profile Picture

Laurens vd Tang 92 Super User 2026 Season 1

#3
Zain Mehmood Profile Picture

Zain Mehmood 89 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans