QueryRange on date

static void QueryOnDate(Args _args)
{
    Query                   query, query2, query3;
    queryRun                qr;
    QueryBuildRange         qbrFromDate, qbrToDate, qbrParentReferenceId, 
                            qbrFromDate2, qbrToDate2, 
                            qbrFromDate3, qbrToDate3;
    QueryBuildDatasource    qbds1, qbds2, qbds3, qbds4;
    InventReferenceItem     inventReferenceItem;
    date                    SysDate = systemDateGet();
    ;

    query       = new Query();
    qbds1       = query.addDataSource(tablenum(MyTable));
    qbrFromDate = qbds1.addRange(fieldnum(MyTable, StartDate));
    qbrToDate   = qbds1.addRange(fieldnum(MyTable, EndDate));
    
    query2          = new Query();
    qbds2           = query2.addDataSource(tablenum(MyTable));
    qbrFromDate2    = qbds2.addRange(fieldnum(MyTable, StartDate));
    qbrToDate2      = qbds2.addRange(fieldnum(MyTable, EndDate));

    query3          = new Query();
    qbds3           = query3.addDataSource(tablenum(MyTable));
    qbrFromDate3    = qbds3.addRange(fieldnum(MyTable, StartDate));
    qbrToDate3      = qbds3.addRange(fieldnum(MyTable, EndDate));


    qbrFromDate.value(SysQuery::range(dateNull(), SysDate));
    qbrToDate.value(SysQuery::range(SysDate, dateNull()));
    
    qbrFromDate2.value(queryValue(dateNull()));
    qbrToDate2.value(queryValue(dateNull()));

    //  Merge of query's
    qbrFromDate3.value(qbrFromDAte.value() + "||" + qbrFromDate2.value());
    qbrToDate3.value(qbrToDate.value() + "||" + qbrToDate2.value());

    qr = new queryRun(query3);
    
    while (qr.next())
    {
        MyTable= qr.get(tablenum(MyTable));
        info(MyTable.ItemId);
    }
    
    info(query3.dataSourceNo(1).toString());
}

AX 2009 feature: cross company support

In X++, there is a new keyword crossCompany you can use in a select statement. Additionally, you can add a container with all the company ID’s you want to include in your select statement.
So, your select statement could look like that:

while select salestable crossCompany : [dmo, cos]
{
... do something ...
}

Now, that’s really a huge step forward from the good old changeCompany function.

Query : make a range with date

Below you can find the code for make a range by a query (with the control if the date is null)

    //  Setup ranges for the date :
    //  FromDate    :   (MyTable.FromDate == dateNull() || MyTable.FromDate <= systemDateGet())
    if (_fromDate)
    {
        qbrFromDate.value(  strfmt("(%1 == %2) || (%1 <= %3)", fieldStr(MyTable, FromDate),   "1/01/1900", _fromDate));
    }

    if (_toDate)
    {
        qbrToDate.value(    strfmt("(%1 == %2) || (%1 >= %3)", fieldStr(MyTable, ToDate),   "1/01/1900", _toDate));
    }

Indicating mandatory field in a dialog (RunBase) class.

A classical problem is indicating that a field is mandatory in a dialog, when the field is not bound to a datasource/field in a datasource.

We can do this by code, but you must forcing the method !

    DialogRunbase       dialog = super();
    ;

    dialog.addGroup("@SYS22142");
    dFromDate       = dialog.addFieldValue(typeId(FromDate), fromDate);
    dToDate         = dialog.addFieldValue(typeId(ToDate), toDate);

    dFromDate.fieldControl().mandatory(true);
    dToDate.fieldControl().mandatory(true);

    return dialog;