Sunday, April 2, 2023

Lookup on form control Dynamics 365 FO on customized form

[Control("String")]
class MCORevisionReasonCodeId
{
    public void lookup()
    {
        Query                   query = new Query();
        QueryBuildDataSource queryBuildDataSource;
        SysTableLookup  sysTableLookup = sysTableLookup::newParameters(tableNum(MCOPORevReasonCodeTable), this);
        queryBuildDataSource = query.addDataSource(tableNum(MCOPORevReasonCodeTable));
        sysTableLookup.addLookupfield(fieldNum(MCOPORevReasonCodeTable, ReasonCodeId),true);
        sysTableLookup.addLookupfield(fieldNum(MCOPORevReasonCodeTable, Description));
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }

    public boolean validate()
    {
        boolean ret;
        ret = super();
        if(ret && !MCOPORevReasonCodeTable::find(this.valueStr()))
        {
            ret = checkFailed(strFmt("@SCM:TableFieldValidation", this.valueStr(), "@MCO:RevReasonCode", "@MCO:PORevReasonCode"));
        }
        return ret;
    }
}