How to Search X++ Code Using Dynamics AX Model Database

By Ramesh Singh | November 27, 2017

How to search x++ code using dynamics ax model database

If you started your development career in Visual Studio and then had to switch to MorphX IDE, one of the features you probably miss is ‘Find in Entire Solution’.

In Visual Studio, the ‘Find’ functionality is very robust – allowing us to search and/or replace in the entire Visual Studio Solution via keywords, matching case, matching whole word and even allowing us to use regular expressions.

'Find' functionality in Video Studio.

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…

'Find' functionality in MorphX IDE.

‘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 '%FDD-003%'

 

The query results took ~26 seconds to find the 7 objects where ‘FDD-003’ is mentioned.

Using a simple SQL query to search for specific X++ code.

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.

Happy coding!

Related Posts

Recommended Reading:

5.27.22 Dynamics GP

How to Run Drop Ship Sales in Dynamics GP

Need to Invoice the Customer before you get the invoice from the vendor? This The freight forwarder has contacted you […]

Read the Article

New Features in Dynamics 365 Business Central 2022 Wave 1 Release – Protecting G/L Accounts From Being Deleted

There are a lot of exciting New Features in Dynamics 365 Business Central 2022 Wave 1 Release to get excited […]

Read the Article
5.25.22 Financials

Rounding Numbers in Power Automate

  If you’ve ever tried to round numbers in Power Automate, you have probably already run into the issue there […]

Read the Article

Manage U.S. Use Tax on Purchase Orders in Dynamics 365 Finance and Operations

  Managing sales tax requirements on your business purchase can be complicated, but Dynamics 365 Finance and Operations can help […]

Read the Article
5.19.22 Dynamics CRM

How to Write a Great Support Ticket in the Stoneridge Support Portal

Submitting a support ticket through the Stoneridge Support Portal is a quick and effective way to get assistance for any […]

Read the Article

Managing Your Business Through Uncertain Times Using Dynamics 365 Finance and Operations

  Dynamics 365 Finance and Operations (F&O) can help you make informed decisions on how to move your business forward. […]

Read the Article
5.13.22 Power Platform

Using Power BI Object Level Security

  The following article will demonstrate how to use Power BI Object Level Security to disable column data based on […]

Read the Article
5.12.22 Dynamics CRM

How to Use the Stoneridge Support Portal

Stoneridge Software’s support portal is an intuitive and useful function that makes it easy for you to access resources to […]

Read the Article
5.6.22 Dynamics GP

Dynamics GP Transaction Removal: Purchase Orders

  Are you having performance issues with Purchase Orders?  Do you find that there are old Purchase Orders on your […]

Read the Article

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!

X