1

I am creating an X++ report, and the requirement is that the user can multi-select on a form and when they click the report menu button the values are pulled in based on the selection.

So far this is easy enough, and I can pull in Str ranges i.e. order numbers, item id's etc, but I want to be able to pull in a date range based on selection.

I have used a method which several MorphX reports use, with use of 3 key methods in X++ reporting;

setQuerySortOrder setQueryEnableDS

and the main key one which is;

setQueryRange

The code for setQuery Range is as follows;

private void setQueryRange(Common _common)
{
    FormDataSource              fds;

    LogisticsControlTable       logisticsTable;
    QueryBuildDataSource        qbdsLogisticsTable;

    QueryBuildRange             qbrVanRun;
    str                         rangeVanRun;

    QueryBuildRange             qbrLogId;
    str                         rangeLogId;

    QueryBuildRange             qbrExpStartDate;
    str                         rangeExpStartDate;

    set                         vanRunSet       = new Set(Types::String);
    set                         logIdSet        = new Set(Types::String);
    set                         expStartDate    = new Set(Types::Date);

    str addRange(str _range, str _value, QueryBuildDataSource _qbds, int _fieldNum, Set _set = null)
    {
    str             ret = _range;
    QueryBuildRange qbr;
    ;

    if(_set && _set.in(_Value))
    {
        return ret;
    }

    if(strLen(ret) + strLen(_value) + 1 > 255)
    {
        qbr = _qbds.addRange(_fieldNum);
        qbr.value(ret);
        ret = '';
    }

    if(ret)
    {
        ret += ',';
    }

    if(_set)
    {
        _set.add(_value);
    }

    ret += _value;
    return ret;
}

switch(_common.TableId)
{
    case tableNum(LogisticsControlTable):

    qbdsLogisticsTable  = element.query().dataSourceTable(tableNum(LogisticsControlTable));
    qbrVanRun           = qbdsLogisticsTable.addRange(fieldNum(LogisticsControlTable, APMServiceCenterID));

    qbdsLogisticsTable  = element.query().dataSourceTable(tableNum(LogisticsControlTable));
    qbrLogId            = qbdsLogisticsTable.addRange(fieldNum(LogisticsControlTable, LogisticsId));

//       qbdsLogisticsTable  = element.query().dataSourceTable(tableNum(LogisticsControlTable));
//        qbrExpStartDate     = qbdsLogisticsTable.addRange(fieldNum(LogisticsControlTable, APMExpDateJobStart));

    fds = _common.dataSource();

    for(logisticsTable = fds.getFirst(true) ? fds.getFirst(true) : _common;
        logisticsTable;
        logisticsTable = fds.getNext())
    {
        rangeVanRun         = addrange(rangeVanRun, logisticsTable.APMServiceCenterID, qbdsLogisticsTable, fieldNum(LogisticsControlTable, APMServiceCenterID), vanRunSet);
        rangeLogID          = addrange(rangeLogID, logisticsTable.LogisticsId, qbdsLogisticsTable, fieldNum(LogisticsControlTable, LogisticsId), logIdSet);
//           rangeExpStartDate   = addrange(rangeExpStartdate,       logisticsTable.APMExpDateJobStart, qbdsLogisticsTable, fieldNum(LogisticsControlTable, APMExpDateJobStart), expStartDate);
    }



qbrLogId.value(rangeLogID);
    qbrVanRun.value(rangeVanRun);
    break;
}
}
Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
will
  • 188
  • 1
  • 4
  • 16
  • The problem I am having is with the commented out lines. The range cannot be Type::Date and this causes issues with the range and values. I've tried adding another new range section but there is no case as with Str. Also tried date2str but unsure where to place this in the code? – will May 29 '12 at 11:00

1 Answers1

0

Use queryValue to format your dates correctly for the query:

set expStartDate = new Set(Types::String);

rangeExpStartDate = addrange(rangeExpStartdate, queryValue(logisticsTable.APMExpDateJobStart), qbdsLogisticsTable, fieldNum(LogisticsControlTable, APMExpDateJobStart), expStartDate);
Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
  • Hi Jan, I had tried this but I get the error; "Error 11, Arguement '_range' is incompatible with the required type." As it is a Date not a string. Would there no utilisation of date2str? – will May 29 '12 at 14:53
  • Did you notice the `queryValue` part of my change? This formats the date as a string suitable for a query. – Jan B. Kjeldsen May 29 '12 at 17:39
  • I added this in yesterday and I still got the error, I try again today and it works. Many thanks again Jan, I'd be lost in MorphX without your guidance :) – will May 30 '12 at 09:40