Sunday, May 27, 2018

How to Search X++ Code Using Dynamics AX Model Database(SQL Server Query)

In MorphX IDE, the ‘Find’ functionality is ‘decent’ and works best if you are searching within an object, like a Class or Table, but if you want to find something across all objects – meaning the entire AOT, it’s probably going to take a long time to search. I lost my patience after waiting for couple hours for the search below to finish…


‘What If’ you could query the Dynamics AX Model Database to find a string across all objects? Well, using the simple SQL Query below, you can. Here’s how to search X++ code using Dynamics AX model database:

SELECT RootHandle.Name RootElementName,
    ElementHandle.Name ElementName,
    ElementTypes.ElementTypeName Type,
    CAST(Sources.SourceText AS nvarchar(MAX)) SourceText
FROM Sources Sources
    JOIN ModelElement ElementHandle
ON Sources.SourceHandle     = ElementHandle.ElementHandle
    JOIN ModelElement RootHandle
ON RootHandle.ElementHandle = ElementHandle.RootHandle
    JOIN ElementTypes ElementTypes
ON ElementTypes.ElementType = ElementHandle.ElementType
WHERE CAST(Sources.SourceText AS nvarchar(MAX)) LIKE '%h.karimi%'



The ‘Where’ clause in the query above can be modified to better fit the text comparison you are looking for, using one of the following SQL operators: =, <>, >, >=, <, <=, IN, BETWEEN, LIKE, IS NULL or IS NOT NULL.
If your requirement is to not look for a string in a method, but instead where the object has been used – ‘Cross Reference’ system in Dynamics AX allows you to see the relationships between objects. For example, you can get a list of every piece of code that uses a particular method, or you can see which forms use a particular table field. You can also get information about where labels are used in the application, but we can’t use the cross reference to look for a string inside a method.
Regards,
Hossein Karimi

No comments:

Post a Comment

Configure the Firewall on the Enterprise Portal Server

After you install Enterprise Portal, enable Web Server (HTTP) in Windows Firewall. If you do not enable the web server in Windows Firewall...