Dynamics crm 2011 未返回正确计数的x++脚本

Dynamics crm 2011 未返回正确计数的x++脚本,dynamics-crm-2011,axapta,x++,Dynamics Crm 2011,Axapta,X++,我有一个x++脚本,它的目标是从select查询中统计记录,并在以后进行更新 这是供参考的原始问题: 最初,我有一个与之对应的SQL查询,结果是50行/记录,当我将其转换为X++时,它不会计算或提取相同数量的记录 这是x++脚本 static void Job(Args _args) { Table1 table1; Table2 table2; Table3 table3; Table4 table4; Table5 table5; int i

我有一个x++脚本,它的目标是从select查询中统计记录,并在以后进行更新

这是供参考的原始问题:

最初,我有一个与之对应的SQL查询,结果是50行/记录,当我将其转换为X++时,它不会计算或提取相同数量的记录

这是x++脚本

static void Job(Args _args)
{

    Table1 table1;
    Table2 table2;
    Table3 table3;
    Table4 table4;
    Table5 table5;
    int i = 0;
    while select forUpdate table1  
       join table2 where table1.field1 == table2.field1 
       join table3 where table1.field2 == table3.field2
       join table4 where table3.field3 == table4.field3
       join table5 where table3.category == table5.recid
       && table1.location  == 'asia' && table2.modtye == 2
       && table3.discount == 'sample' 
       && table4.name ==  'hello' 
       &&(table5.name == 'one' || table5.name == 'two' || table5.name == 'three')                
    {    
            if (table1)    
            {
                 i = i + 1;    
            }    
    }    
    info(strfmt("Total : %1",i));    
}
请帮忙,我哪里出了问题?我想是这部分出了问题

if (table1)
我还试着删减代码以知道问题出在哪里

 while select forUpdate table1  
           join table2 where table1.field1 == table2.field1 
           && table1.location  == 'asia' && table2.modtye == 2
此部分尚未返回结果。。。当我包括

 && table1.location  == 'asia' && table2.modtye == 2
所以我认为,问题是存在的,但是代码有什么问题

我的代码实际上是基于这个教程链接


我建议一个简单的解释,也许SQL返回来自多个公司或分区的行? 默认情况下,AX仅返回当前分区和公司curext的行

如果使用crosscompany选项选择,它将扫描跨公司:

while select crosscompany table1 ...
您不需要测试是否找到表1,如果没有找到,它将不会进入循环

此外,如果您的唯一目的是统计手动统计的记录数是浪费时间的,则只需进行一次选择即可:

select firstOnly /*crosscompany*/ count(RecId) from table1  
   exists join table2 where table1.field1 == table2.field1 
   exists join table3 where table1.field2 == table3.field2
   exists join table4 where table3.field3 == table4.field3
   exists join table5 where table3.category == table5.recid
     && table1.location  == 'asia' && table2.modtye == 2
     && table3.discount == 'sample' 
     && table4.name ==  'hello' 
     &&(table5.name == 'one' || table5.name == 'two' || table5.name == 'three');
info(strfmt("Total : %1", table1.RecId));

是否应该是-如果表1?是的。。我已经编辑过了。仍然不起作用我已经编辑了我的问题以进行一些查找您可以检查SQL脚本是否有与直接在数据库中执行时返回数据相同的逻辑。SQL中的内部联接匹配X++中的联接。我明白了,但我的目标实际上是根据查询的结果集更新记录。我只是试图通过创建一个计数器来简化这个问题,以测试我在SQL中的结果集是否与X++对应的结果集匹配。所以,当它已经匹配,我可以自信地更新记录。好,考虑第一部分的答案。通常,您希望将更新限制在当前公司,因此在这种情况下,crosscompany不是一个好主意。对不起,推荐的答案是什么?我应该使用crosscompany?如果使用crosscompany,它的计数可能与SQL相同。但你真的想更新所有记录而不考虑公司吗?事实上,我也放了这行:table1.location=='asia',因为这将过滤掉每个公司的标准,所以它只包含来自asia location的结果…该位置表示公司