x++ 中的 strfmt 范围

strfmt range in x++

这个范围有什么问题?

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

我收到这个错误:

Query extended range error: Right parenthesis expected next to position 72.

AX 2012 documentation 的这一页仍然相关(我找不到 AX365 版本)。突出显示重要位给出:

The rules for creating query range value expressions are:

  • Enclose the whole expression in parentheses.
  • Enclose all subexpressions in parentheses.
  • Use the relational and logical operators available in X++.
  • Only use field names from the range's data source.
  • Use the dataSource.field notation for fields from other data sources in the query.

这意味着 X++ 需要在 每个 比较运算符(文档中的 a.k.a.“子表达式”)周围使用大括号。你错过了一些...

此外,使用 date2strxpp() 函数正确处理所有日期到字符串的转换。此函数可以通过将这些值转换为 1900-01-01 来处理空日期值 (dateNull())。我怀疑在其中放置一个空字符串 (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()));