首页 > 解决方案 > x++ 中的 strfmt 范围

问题描述

这个范围有什么问题?

rangeTransDate = strFmt('(("%1.%2" <= "%3" && "%3" == "%5") || ("%1.%4" > "%3"))',tableStr(CustomTable),fieldStr(CustomTable,TransDate), date2str(dateTo,321,2,0,2,0,4),fieldStr(CustomTable,SettlementDate),SysQuery::valueEmptyString());

我收到此错误:

查询扩展范围错误:位置 72 旁边应有右括号。

标签: microsoft-dynamicsx++dynamics-365

解决方案


AX 2012 文档的此页面仍然相关(我找不到 AX365 版本)。突出显示重要的部分给出:

创建查询范围值表达式的规则是:

  • 将整个表达式括在括号中。
  • 将所有子表达式括在括号中。
  • 使用 X++ 中可用的关系和逻辑运算符。
  • 仅使用范围数据源中的字段名称。
  • 对查询中其他数据源的字段使用 dataSource.field 表示法。

这意味着 X++ 需要在每个比较运算符(也称为文档中的“子表达式”)周围加上大括号。你少了一些...

此外,使用该date2strxpp()函数正确处理所有日期到字符串的转换。此函数可以通过将空日期值 ( dateNull()) 转换为1900-01-01. 我怀疑在其中放一个空字符串 ( SysQuery::valueEmptyString()) 会起作用。

所以试试这个,注释的子表达式级别显示括号分组:

// subexpressions lvl 2: 4                                                       4
// subexpressions lvl 1: |1               1    2            2    3              3|
//                       ||               |    |            |    |              ||
rangeTransDate = strFmt('(("%1.%2" <= "%3") && ("%3" == "%5") || ("%1.%4" > "%3"))',
                        tableStr(CustomTable),
                        fieldStr(CustomTable,TransDate),
                        date2strxpp(dateTo),
                        fieldStr(CustomTable,SettlementDate),
                        date2strxpp(dateNull()));

如果您在运行时仍然遇到类似的错误,请添加更多括号将每个子表达式成对分组:

// subexpressions lvl 3: 5                                                         5
// subexpressions lvl 2: |4                                   4    3              3|
// subexpressions lvl 1: ||1               1    2            2|    3              3|
//                       |||               |    |            ||    |              ||
rangeTransDate = strFmt('((("%1.%2" <= "%3") && ("%3" == "%5")) || ("%1.%4" > "%3"))',
                        tableStr(CustomTable),
                        fieldStr(CustomTable,TransDate),
                        date2strxpp(dateTo),
                        fieldStr(CustomTable,SettlementDate),
                        date2strxpp(dateNull()));

推荐阅读