2012-09-07 2 views
1

이 코드는 모든 AX 시스템에서 실행 가능해야합니다 (변경 사항 &웨어 하우스). 문제는 CustInvoiceJour가 가끔 반환되지 않는다는 것입니다. 이상한 점은, 같은 관계로 "select custInvoiceJour"를 수행하면 찾을 수 있습니까? 이것이 어떻게 가능한지?쿼리 개체가 예상대로 작동하지 않습니까?

static void Job59(Args _args) 
{ 
    CustInvoiceTrans   custInvoiceTrans; 
    CustInvoiceJour    custInvoiceJour; 
    InventTable    inventTable; 
    QueryBuildRange    rangeItem; 
    Query      query; 
    QueryBuildDataSource  qbds1; 
    QueryBuildDataSource  qbds2; 
    QueryBuildDataSource  qbds3; 
    QueryRun     qr; 
    ; 

    query = new Query(); 
    qbds1 = query.addDataSource(tablenum(CustInvoiceTrans)); 
    qbds2 = qbds1.addDataSource(tablenum(CustInvoiceJour)); 
    qbds2.relations(true); 

    qbds2.addRange(fieldnum(CustInvoiceJour, SalesType)).value('!' + enum2str(SalesType::ReturnItem)); 
    rangeItem = qbds1.addRange(fieldnum(CustInvoiceTrans, ItemId)); 
    qbds1.addRange(fieldnum(CustInvoiceTrans, InvoiceDate)).value(queryRange(@'8/1/2011', @'8/31/2011')); 
    qbds2.orderMode(OrderMode::OrderBy); 
    qbds2.addOrderByField(fieldnum(CustInvoiceJour, DlvCountryRegionId)); 
    qbds2.addOrderByField(fieldnum(CustInvoiceJour, DlvState)); 
    qbds3 = qbds1.addDataSource(tablenum(InventDim)); 
    qbds3.relations(true); 
    qbds3.joinMode(JoinMode::ExistsJoin); 
    qbds3.addRange(fieldnum(InventDim, InventLocationId)).value(SysQuery::value('FG')); 


    select firstonly inventTable 
     where inventTable.ItemId == '44831'; 

    info (strfmt("%1", inventTable.ItemId)); 
    rangeItem.value(inventTable.ItemId); 

    qr = new QueryRun(query); 
    while (qr.next()) 
    { 
     custInvoiceTrans = qr.get(tablenum(CustInvoiceTrans)); 
     custInvoiceJour  = qr.get(tablenum(CustInvoiceJour)); 

     if (!custInvoiceJour) 
     { 
      info ("Not found"); 
      select firstonly custInvoiceJour 
       where custInvoiceJour.SalesId    == custInvoiceTrans.SalesId  && 
         custInvoiceJour.InvoiceId    == custInvoiceTrans.InvoiceId && 
         custInvoiceJour.InvoiceDate   == custInvoiceTrans.InvoiceDate && 
         custInvoiceJour.numberSequenceGroup == custInvoiceTrans.numberSequenceGroup; 
      if (custInvoiceJour) 
       info("Found it"); 
     } 
    } 
} 

디버거는 쿼리 이러한 보여줍니다 :

NAME: 
    qbds1 
VALUE: 
    SELECT * FROM CustInvoiceTrans ORDER BY CustInvoiceJour.DlvCountryRegionId ASC, CustInvoiceJour.DlvState ASC WHERE ((ItemId = N'44831')) AND ((InvoiceDate>={ts '2011-08-01 00:00:00.000'} AND InvoiceDate<={ts '2011-08-31 00:00:00.000'})) EXISTS JOIN * FROM InventDim WHERE CustInvoiceTrans.InventDimId = InventDim.inventDimId AND ((InventLocationId = N'FG')) 

NAME: 
    qbds2 
VALUE: 
    SELECT * FROM CustInvoiceJour WHERE CustInvoiceTrans.SalesId = CustInvoiceJour.SalesId AND CustInvoiceTrans.InvoiceId = CustInvoiceJour.InvoiceId AND CustInvoiceTrans.InvoiceDate = CustInvoiceJour.InvoiceDate AND CustInvoiceTrans.numberSequenceGroup = CustInvoiceJour.numberSequenceGroup AND ((NOT (SalesType = 4))) 


NAME: 
    qbds3 
VALUE: 
    SELECT * FROM InventDim WHERE CustInvoiceTrans.InventDimId = InventDim.inventDimId AND ((InventLocationId = N'FG')) 

답변

2

귀하의 qbds1 값이 JOIN * FROM CustInvoiceJour WHERE ... (가입 qbds2)를 표시하지 않습니다.

코드에 qbds2.fetchMode(QueryFetchMode::One2One);을 추가하면 모든 것이 올바르게 처리됩니다.

P. 나는 다른 방향으로 그것을 할 것을 제안한다 : qbds1의 CustInvoiceJour와 qbds2의 CustInvoiceTrans (디폴트는 fetchMode). 그러면이 문제는 전혀 발생하지 않을 것이다.

+0

실제로 일부 기존 코드를 수정/디버깅하고 있습니다. 나는 논리가 우리가 라인에서 아이템을 찾고 있기 때문에 라인으로 시작한다고 생각합니다. 이상한 것은 CustInvoiceJour가 절반의 시간 반품되었다는 것입니다. 고마워! –

관련 문제