Wednesday, September 19, 2018

Find AX code snippets from SQL end like a cross reference on AX but from SQL side

I recently learned a way to find code snippets quickly using sql. This is very helpful in scenarios when cross reference is turned off and you need to find places where a particular class or function is being called from.

On the model database on sql you can write the below query and you should be able to see all the methods where that code is called from.


SELECT RootHandle.Name                                              RootElementName,
    ElementHandle.Name                                               ElementName,
    ElementTypes.ElementTypeName                              Type,
    CAST(Sources.SourceText AS nvarchar(MAX))                 SourceText
FROM Sources Sources (nolock)
    JOIN ModelElement ElementHandle (nolock)
              ON Sources.SourceHandle        = ElementHandle.ElementHandle
    JOIN ModelElement RootHandle (nolock)
              ON RootHandle.ElementHandle = ElementHandle.RootHandle
    JOIN ElementTypes ElementTypes (nolock)
              ON ElementTypes.ElementType = ElementHandle.ElementType
WHERE CAST(Sources.SourceText AS nvarchar(MAX)) LIKE '%code to search for%'
OPTION(MAXDOP 0)

1 comment:

  1. You can also join with the layer table to only see records from anything higher than syp layer
    join dbo.Layer layerT
    on layert.Id = sources.LayerId
    WHERE layerT.Id > 2

    ReplyDelete