Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Get the query from view.

Posted on by Microsoft Employee

Hello,

Is there any way to get the query object from view object?

(i.e get the query that represented the query behind the view: DirPartyPostalAddressView)

 

Thanks :)

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get the query from view.

    For query - I figure out how, so I succeeded getting the query object, but when the case is on 'data sources' - I I presume I must add the datasource in code, so need to loop over all the data sources elements properties.

    I didn't see any properties iterator so I can loop through.

    Thanks :)

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 228,041 Super User 2024 Season 2 on at
    RE: Get the query from view.

    When you know the query name, you can pass it to the constructor of the Query class (new Query('xyz')). Sorry, I thought you already knew that.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get the query from view.

    Still don't understand how create an object instance from the current treeNode as my original post.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 228,041 Super User 2024 Season 2 on at
    RE: Get the query from view.

    AOTnextSibling() is the right syntax for getting the next sibling. If you want to get something else, use another method. For example, if you want to get the first child, call AOTfirstChild(). It isn't that complicated. :-)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get the query from view.

    Thank you.

    That's what I am looking for.

    I have a code like this:

        TreeNode    treeNode;
        #AOT
    
        str s;
    
    treeNode = treeNode::findNode(#ViewsPath + '\\' + tablestr(DirPartyPostalAddressView) + '\\MetaData');
        while (treeNode)
        {
            s = treeNode.treeNodeName();
            switch(s)
            {
                case 'data sources':
                // need to get the object
                    break;
                default:
                // need to get the object
                    break;
            }
            treeNode = treeNode.AOTnextSibling();
        }
    


    I presume AOTnextSibling is not the right syntax (I am not looping through the LogisticsPostalAddress object).

    I need to get the object that is behind LogisticsPostalAddress or data sources object.

     

    Thanks :)

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 228,041 Super User 2024 Season 2 on at
    RE: Get the query from view.

    Use the TreeNode API to analyze the view definition.

  • dekaasboer Profile Picture
    dekaasboer 1,530 on at
    RE: Get the query from view.

    Do you have database access on your enviroment?

    For me the simplest method has allways been to look the view up in ssms.

    If there is a easier way I would shure like to know.

    Your view btw:

    CREATE VIEW [dbo].[DIRPARTYPOSTALADDRESSVIEW] AS SELECT T1.PARTY AS PARTY,T1.RECID AS PARTYLOCATION,T1.ISPRIMARY AS ISPRIMARY,T1.ISLOCATIONOWNER AS ISLOCATIONOWNER,T1.ISPRIMARYTAXREGISTRATION AS ISPRIMARYTAXREGISTRATION,T1.PARTITION AS PARTITION,T1.RECID AS RECID,T2.PARTITION AS PARTITION#2,T2.LOCATIONNAME AS LOCATIONNAME,T2.ADDRESS AS ADDRESS,T2.STREETNUMBER AS STREETNUMBER,T2.STREET AS STREET,T2.CITY AS CITY,T2.ZIPCODE AS ZIPCODE,T2.STATE AS STATE,T2.COUNTY AS COUNTY,T2.COUNTRYREGIONID AS COUNTRYREGIONID,T2.DISTRICT AS DISTRICT,T2.POSTBOX AS POSTBOX,T2.BUILDINGCOMPLIMENT AS BUILDINGCOMPLIMENT,T2.TIMEZONE AS TIMEZONE,T2.LONGITUDE AS LONGITUDE,T2.LATITUDE AS LATITUDE,T2.LOCATION AS LOCATION,T2.VALIDFROM AS VALIDFROM,T2.VALIDTO AS VALIDTO,T2.COUNTRYCURRENCYCODE AS COUNTRYCURRENCYCODE,T2.ISPRIVATE AS ISPRIVATE,T2.DISTRICTNAME AS DISTRICTNAME,T2.POSTALADDRESS AS POSTALADDRESS,T2.ISOCODE AS ISOCODE,T2.STREETID_RU AS STREETID_RU,T2.HOUSEID_RU AS HOUSEID_RU,T2.FLATID_RU AS FLATID_RU,T2.BUILDING_RU AS BUILDING_RU,T2.APARTMENT_RU AS APARTMENT_RU,T2.PRIVATEFORPARTY AS PRIVATEFORPARTY,T2.XRECID_LOGISTICSPOSTALADDRESS AS XRECID_LOGISTICSPOSTALADDRESS,T2.XRECVERSION_LOGISTICSPOSTALADDRESS AS XRECVERSION_LOGISTICSPOSTALADDRESS,T2.CITYRECID AS CITYRECID FROM  DIRPARTYLOCATION T1 LEFT OUTER JOIN LOGISTICSPOSTALADDRESSVIEW T2 ON (T1.LOCATION=T2.LOCATION AND (T1.PARTITION = T2.PARTITION)) WHERE (T1.ISPOSTALADDRESS=1)

    GO

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get the query from view.

    The view is built in AX AOT.

    I need some X++ code to figure out what are the objects behinds the DirPartyPostalAddressView object (it is a view, but also an object in AOT), and I can go on from that point.

    I see that there is a query object (not all the views), so I need to get that object.

    Thanks :)

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 228,041 Super User 2024 Season 2 on at
    RE: Get the query from view.

    You can analyze the view definition in AOT. The actual view in SQL Server obviously doesn't know anything about any query in Dynamics AX.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,246 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,041 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans