【问题标题】:Dynamics AX 2009 X++ Selecting A Date RangeDynamics AX 2009 X++ 选择日期范围
【发布时间】:2015-09-01 14:56:17
【问题描述】:

我正在创建一个 X++ 报表,要求是用户可以在表单上进行多选,当他们单击报表菜单按钮时,会根据选择拉入值。

到目前为止,这很容易,我可以提取 Str 范围,即订单号、商品 ID 等,但我希望能够根据选择提取日期范围。

我使用了几个 MorphX 报告使用的方法,在 X++ 报告中使用了 3 个关键方法;

setQuerySortOrder setQueryEnableDS

和主要的关键之一是;

设置查询范围

setQuery Range的代码如下;

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;
}
}

【问题讨论】:

  • 我遇到的问题是注释掉的行。范围不能是 Type::Date,这会导致范围和值出现问题。我尝试添加另一个新的范围部分,但没有像 Str 那样的情况。也尝试过 date2str 但不确定将其放在代码中的哪个位置?

标签: axapta x++ microsoft-dynamics ax


【解决方案1】:

使用queryValue 为查询正确设置日期格式:

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

rangeExpStartDate = addrange(rangeExpStartdate, queryValue(logisticsTable.APMExpDateJobStart), qbdsLogisticsTable, fieldNum(LogisticsControlTable, APMExpDateJobStart), expStartDate);

【讨论】:

  • 嗨 Jan,我试过这个,但我得到了错误; “错误 11,参数 '_range' 与所需类型不兼容。”因为它是日期而不是字符串。不会使用 date2str 吗?
  • 您注意到我更改的queryValue 部分了吗?这会将日期格式化为适合查询的字符串。
  • 我昨天添加了这个,但我仍然收到错误,我今天再试一次,它可以工作。再次感谢 Jan,如果没有你的指导,我会迷失在 MorphX 中的 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-08
相关资源
最近更新 更多