2012-01-11 91 views
1

我試圖在VendTrans和VendTable之間創建一個簡單的跨公司查詢。我們啓用了全球通訊錄,因此有些條目在公司之間共享。如果我在寫SQL,它看起來像:Dynamics AX與VendTrans和全局地址簿的跨公司查詢

select vtxn.Voucher, vtxn.TransDate, vt.AccountNum, vt.Name 
from dbo.vendtrans vtxn 
join dbo.vendtable vt on vtxn.accountnum = vt.accountnum 
    and vt.dataareaid in (vtxn.dataareaid, 'shr') 

我遇到的問題是,由於全局地址簿的,我得到下面沒有定義的查詢和查看結果。我將不勝感激任何幫助。

謝謝。

 
QUERY #spTestQuery 
    PROPERTIES 
    Name    #spTestQuery 
    UserUpdate   #No 
    Version    #524 
    NextUniqueId  #1008 
    AllowCrossCompany #Yes 
    ENDPROPERTIES 

    METHODS 
    Version: 3 
    SOURCE #classDeclaration 
     #public class QueryRun extends ObjectRun 
     #{ 
     #} 
    ENDSOURCE 
    ENDMETHODS 
    BLOCKS 
    BLOCK #LedgerJournalTrans 
     PROPERTIES 
     Name    #LedgerJournalTrans_1 
     Table    #LedgerJournalTrans 
     UniqueId   #1000 
     FirstFast   #Yes 
     AllowAdd   #No fields 
     ENDPROPERTIES 

     FIELDLIST 
     PROPERTIES 
      Dynamic    #No 
     ENDPROPERTIES 

     FIELD #BankChequeNum 
     FIELD #TransDate 
     ENDFIELDLIST 
     SORTING 
     ENDSORTING 
     LINES 
     LINE #BankChequeNum 
     PROPERTIES 
      Name    #BankChequeNum 
      Table    #LedgerJournalTrans 
      Field    #BankChequeNum 
      Value    #> 0 
     ENDPROPERTIES 

     ENDLINES 
     BLOCKS 
     BLOCK #VendTrans 
      PROPERTIES 
      Name    #VendTrans_1 
      Table    #VendTrans 
      UniqueId   #1003 
      AllowAdd   #No fields 
      FetchMode   #1:1 
      Relations   #Yes 
      ENDPROPERTIES 

      FIELDLIST 
      PROPERTIES 
       Dynamic    #No 
      ENDPROPERTIES 

      FIELD #AccountNum 
      FIELD #LastSettleVoucher 
      ENDFIELDLIST 
      SORTING 
      ENDSORTING 
      LINES 
      ENDLINES 
      BLOCKS 
      BLOCK #VendTable 
       PROPERTIES 
       Name    #VendTable_1 
       Table    #VendTable 
       UniqueId   #1004 
       Relations   #Yes 
       Enabled    #No 
       ENDPROPERTIES 

       FIELDLIST 
       PROPERTIES 
        Dynamic    #No 
       ENDPROPERTIES 

       FIELD #Name 
       FIELD #AccountNum 
       ENDFIELDLIST 
       SORTING 
       ENDSORTING 
       LINES 
       ENDLINES 
       BLOCKS 
       ENDBLOCKS 
       ASSOCIATIONS 
       ASSOCIATION 
        MASTERFIELD #AccountNum 
        DETAILSFIELD #AccountNum 
       ENDASSOCIATIONS 
      ENDBLOCK 
      ENDBLOCKS 
      ASSOCIATIONS 
      ASSOCIATION 
       MASTERFIELD #AccountNum 
       DETAILSFIELD #AccountNum 
      ENDASSOCIATIONS 
     ENDBLOCK 
     BLOCK #LedgerTrans 
      PROPERTIES 
      Name    #LedgerTrans_1 
      Table    #LedgerTrans 
      UniqueId   #1005 
      AllowAdd   #No fields 
      FetchMode   #1:1 
      Relations   #Yes 
      ENDPROPERTIES 

      FIELDLIST 
      PROPERTIES 
       Dynamic    #No 
      ENDPROPERTIES 

      FIELD #AccountNum 
      FIELD #Voucher 
      FIELD #AmountMST 
      FIELD #TransDate 
      FIELD #Voucher 
      FIELD #Dimension 
      ENDFIELDLIST 
      SORTING 
      ENDSORTING 
      LINES 
      LINE #AccountNum 
      PROPERTIES 
       Name    #AccountNum 
       Table    #LedgerTrans 
       Field    #AccountNum 
       Value    #!211000 
      ENDPROPERTIES 

      ENDLINES 
      BLOCKS 
      BLOCK #LedgerTable 
       PROPERTIES 
       Name    #LedgerTable_1 
       Table    #LedgerTable 
       UniqueId   #1006 
       AllowAdd   #No fields 
       Relations   #Yes 
       ENDPROPERTIES 

       FIELDLIST 
       PROPERTIES 
        Dynamic    #No 
       ENDPROPERTIES 

       FIELD #AccountName 
       FIELD #AccountNum 
       ENDFIELDLIST 
       SORTING 
       ENDSORTING 
       LINES 
       ENDLINES 
       BLOCKS 
       ENDBLOCKS 
       ASSOCIATIONS 
       ASSOCIATION 
        MASTERFIELD #AccountNum 
        DETAILSFIELD #AccountNum 
       ENDASSOCIATIONS 
      ENDBLOCK 
      BLOCK #Dimensions 
       PROPERTIES 
       Name    #Dimensions_1 
       Table    #Dimensions 
       UniqueId   #1007 
       AllowAdd   #No fields 
       ENDPROPERTIES 

       FIELDLIST 
       PROPERTIES 
        Dynamic    #No 
       ENDPROPERTIES 

       FIELD #Description 
       FIELD #Num 
       FIELD #DimensionCode 
       ENDFIELDLIST 
       SORTING 
       ENDSORTING 
       LINES 
       LINE #DimensionCode 
       PROPERTIES 
        Name    #DimensionCode 
        Table    #Dimensions 
        Field    #DimensionCode 
        Value    #Purpose 
       ENDPROPERTIES 

       ENDLINES 
       BLOCKS 
       ENDBLOCKS 
       ASSOCIATIONS 
       ASSOCIATION 
        JOINDATASOURCE #LedgerTrans_1 
        MASTERFIELD #Dimension[3] 
        DETAILSFIELD #Num 
       ENDASSOCIATIONS 
      ENDBLOCK 
      ENDBLOCKS 
      ASSOCIATIONS 
      ASSOCIATION 
       MASTERFIELD #TransDate 
       DETAILSFIELD #TransDate 
      ASSOCIATION 
       MASTERFIELD #Voucher 
       DETAILSFIELD #Voucher 
      ENDASSOCIATIONS 
     ENDBLOCK 
     ENDBLOCKS 
     GROUPBY 
     ENDGROUPBY 
     ORDERBY 
     ENDORDERBY 
    ENDBLOCK 
    ENDBLOCKS 
    DEPENDENTS 
    DEPENDENT 
     PROPERTIES 
     Name    #spTestView 
     DependentType  #View 
     ENDPROPERTIES 

     Id 50005 
    ENDDEPENDENTS 
    COMPOSITEQUERIES 
    ENDCOMPOSITEQUERIES 
ENDQUERY 

    VIEW #spVendTestView 
    Id 50008 
    PROPERTIES 
     Name    #spVendTestView 
     SaveDataPerCompany #Yes 
     Query    #spvendtest 
    ENDPROPERTIES 

    QUERY #Metadata 
     PROPERTIES 
     Name    #Metadata 
     AllowCrossCompany #Yes 
     ENDPROPERTIES 

     BLOCKS 
     ENDBLOCKS 
     QUERY #spVendTest 
     ENDQUERY 

    ENDQUERY 

    FIELDS 
     VIEWFIELD #Voucher 
     Id 50001 
     PROPERTIES 
      Name    #Voucher 
      Table    #spVendTestView 
      ExtendedDataType #Voucher 
      StringSize   #25 
      DataSource   #VendTrans_1 
      DataField   #Voucher 
     ENDPROPERTIES 

     ENDVIEWFIELD 

     VIEWFIELD #TransDate 
     Id 50003 
     PROPERTIES 
      Type    #Date 
      Name    #TransDate 
      Table    #spVendTestView 
      ExtendedDataType #TransDate 
      StringSize   #(Memo) 
      DataSource   #VendTrans_1 
      DataField   #TransDate 
     ENDPROPERTIES 

     ENDVIEWFIELD 

     VIEWFIELD #AccountNum 
     Id 50004 
     PROPERTIES 
      Name    #AccountNum 
      Table    #spVendTestView 
      ExtendedDataType #VendAccount 
      StringSize   #20 
      DataSource   #VendTable_1 
      DataField   #AccountNum 
     ENDPROPERTIES 

     ENDVIEWFIELD 

     VIEWFIELD #Name 
     Id 50002 
     PROPERTIES 
      Name    #Name 
      Table    #spVendTestView 
      ExtendedDataType #VendName 
      StringSize   #120 
      DataSource   #VendTable_1 
      DataField   #Name 
     ENDPROPERTIES 

     ENDVIEWFIELD 

    ENDFIELDS 
    GROUPS 
    ENDGROUPS 

    ENDVIEW 

回答

2

我可以看到你用crosscompany定義查詢,然後根據查詢定義一個視圖。 但是查詢中的crosscompany並不意味着該視圖也是crosscompany

看一看Cross-Company Queries for Views

摘錄:

In the Application Object Tree (AOT), you can build a view by dragging a query node onto the Data Sources node of your view. The query could have the AllowCrossCompany property set to Yes. However, this will not return cross-company results from the view.

To return cross-company results from a view, you need to use the crossCompany keyword on the select statement that reads from the view. The AllowCrossCompany setting on the view's data source query is ignored in X++ select statements that read from a view.

+0

試過添加元數據節點下設置AllowCrossCompany爲是。 使用下面的查詢:SELECT crossCompany * FROM spVendTestView 得到這個錯誤: 使用X ++來選擇由表單數據源所擁有的跨公司表中的記錄不被支持。 – saarp 2012-01-12 18:35:21

+0

你是否嘗試過直接使用查詢來實現表單?或者,您可以使用常規的舊式表單數據源。 – 2012-01-12 21:42:34

+0

不確定你的意思。上面的代碼是一個查詢,其中查詢定義爲查詢作爲數據源。不一定使用這個報告。無論哪種方式,這應該可能會返回一些東西。 – saarp 2012-01-14 07:12:38