Thursday 10 January 2019

Lookups In D365


1.  Build query through lookup method :

/// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormControlEventHandler(formControlStr(PurchTable, NCMR_OINCMRDispositionCodeId_011), FormControlEventType::Lookup)]
    public static void NCMR_OINCMRDispositionCodeId_011_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        FormRun             formRun          = sender.formRun();
        FormStringControl    NCMRDispositionCode = formRun.design(0).controlName("NCMR_OINCMRDispositionCodeId_011");
        Query query = new Query();
        QueryBuildDataSource qbds;
        SysTableLookup sysTableLookup;
        sysTableLookup = SysTableLookup::newParameters(tableNum(OINCMRDispositionCode), sender);
        sysTableLookup.addLookupfield(fieldNum(OINCMRDispositionCode,NCMRDispositionCodeId));
        sysTableLookup.addLookupfield(fieldNum(OINCMRDispositionCode, Description));
        qbds = query.addDataSource(tableNum(OINCMRDispositionCode));
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }

}

2. Build Lookup using Reference Table Lookup :

 [FormControlEventHandler(formControlStr(CustParameters, FormGroupControl1_EQNStandardDayRateCodeint), FormControlEventType::Lookup)]
    public static void FormGroupControl1_EQNStandardDayRateCodeint_OnLookup(FormControl sender, FormControlEventArgs e)
    {        
        CustParameterEventhandler::createLookup(sender);     
    }

    private static void createLookup(FormReferenceGroupControl _ctrl)
    {
        SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup::newParameters(tablenum(UnitOfMeasure), _ctrl);
        Query                   query = new Query();
        QueryBuildDataSource    unitMeasureDS;
        unitMeasureDS   =   query.addDataSource(tableNum(UnitOfMeasure));
        unitMeasureDS.addRange(fieldNum(UnitOfMeasure,UnitOfMeasureClass)).value(SysQuery::value(UnitOfMeasureClass::Time));
        sysTableLookup.addLookupfield(fieldNum(UnitOfMeasure,Symbol));
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }

No comments:

Post a Comment