Tuesday, 26 June 2018

Filter Grid in D365 based on lookup of Some unbound control

I have  a task to filter the grid based on unbound Enum control ( Show - All/ErrorLines)

class CITLedgerJournalTransCustPaym
{
    QueryBuildRange        citErrorLog;

   
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormControlEventHandler(formControlStr(LedgerJournalTransCustPaym, Show), FormControlEventType::SelectionChanged)]
    public static void Show_OnSelectionChanged(FormControl sender, FormControlEventArgs e)
    {
        FormDatasource          fds;
        FormControl             CITError;
        FormRun                 element;
        QueryBuildRange        citErrorLog;
       
        element     = sender.FormRun();
        CITError    =   element.design(0).controlName('Show');
        fds         = element.dataSource(formDataSourceStr(LedgerJournalTransCustPaym, LedgerJournalTrans)) as FormDataSource;
        citErrorLog = fds.query().dataSourceTable(tableNum(LedgerJournalTrans)).findRange(fieldNum(LedgerJournalTrans,CITErrorLog));
       
        if(citErrorLog == null)
        {
            citErrorLog  = fds.query().dataSourceTable(tableNum(LedgerJournalTrans)).addRange(fieldNum(LedgerJournalTrans, CITErrorLog));
        }
     
        if(CITError.valueStr() == enum2Str(CITShow::Errorlines))
        {
            citErrorLog.value(enum2Str(NoYes::Yes));
        }
        else
        {
            citErrorLog.value(SysQuery::valueUnlimited());
           // ;
        }
       
        fds.executeQuery();
        fds.reread();
        fds.refresh();
       
        //QueryBuildRange = Table_ds.query().dataSourceName(“datasource name”).addRange(fieldNum(Table,field)).value(enum2str(enum.selection()));
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormDataSourceEventHandler(formDataSourceStr(LedgerJournalTransCustPaym, LedgerJournalTrans), FormDataSourceEventType::Initialized)]
    public static void LedgerJournalTrans_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
    {
        //fds                 = sender.formRun().datasource('LedgerJournalTrans');
        //citErrorLog = fds.query().dataSourceTable(tableNum(LedgerJournalTrans)).addRange(fieldNum(LedgerJournalTrans,CITErrorLog));

    }


}

No comments:

Post a Comment