Warm tip: This article is reproduced from serverfault.com, please click

microsoft dynamics-X ++中的strfmt范围

(microsoft dynamics - strfmt range in x++)

发布于 2020-12-02 16:14:52

这个范围怎么了?

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旁边。

Questioner
OiRc
Viewed
0
Sander 2020-12-04 03:58:18

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()));