web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Regex in QueryBuildRange value?

(0) ShareShare
ReportReport
Posted on by

Is it possible to use regular expressions in QueryBuildRange value method? 

I want to get the name of the countries that start with an English Alphabet (a-zA-Z). 


The SQL query is working perfectly in the SQL Server Management Studio and is as:

select TRANS.COUNTRYREGIONID, SHORTNAME from 
[AxDB].[ax].[LOGISTICSADDRESSCOUNTRYREGIONTRANSLATION] as TRANS,
[AxDB].[ax].[LOGISTICSADDRESSCOUNTRYREGION] as COUNTRY
where COUNTRY.COUNTRYREGIONID = TRANS.COUNTRYREGIONID
and SHORTNAME like '[a-zA-Z]%'
group by TRANS.COUNTRYREGIONID, SHORTNAME;

The query returns the following (only 3 records are shown to indicate what I am trying to achieve):

CountryRegionIdShortName
AUS Australia
ARG Argentina
BRA Brazil
... ...

The LogisticsAddressCountryRegion and LogisticsAddressCountryRegionTranslation have been added to a form as FormDataSource, and LogisticsAddressCountryRegionTranslation is InnerJoin'd to the LogisticsAddressCountryRegion via CountryRegionId foreign key relation. What I want is to display the CountryRegionId and ShortName on a grid control on a form and have changed the parent datasource's executeQuery() method as:

        public void executeQuery()
        {
this.query().dataSourceTable(tableNum(LogisticsAddressCountryRegionTranslation)) .addRange(fieldNum(LogisticsAddressCountryRegionTranslation, ShortName)) .value(Global::queryValue('[a-zA-Z]*')); this.query().dataSourceTable(tableNum(LogisticsAddressCountryRegion)) .addGroupByField(fieldNum(LogisticsAddressCountryRegion, CountryRegionId)); this.query().dataSourceTable(tableNum(LogisticsAddressCountryRegionTranslation)) .addGroupByField(fieldNum(LogisticsAddressCountryRegionTranslation, ShortName)); super(); }

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,978 Most Valuable Professional on at

    You don't need distinguishing between lowercase and upper-case, because AX database isn't case sensitive.

    But AX doesn't allow you to use regular expressions in the WHERE clauses; it supports only wildcards (* and ?). You would have to find a different solution (e.g. two conditions, 'higher or to equal to a' and 'lower or equal to z'). If you're dealing with data corruption (instead of writing normal business logic), am direct SQL query may be the best option.

  • Community Member Profile Picture
    on at

    What do you mean by direct SQL query? Is there a way to overwrite the base query for a particular datasource object using string literal representation i.e. "select * from xyz"?

    and thank you, the solution worked perfectly using .value(Global::queryRange('a*', 'z*'));

  • Martin Dráb Profile Picture
    237,978 Most Valuable Professional on at

    I mean that you could open SQL Server Management Studio in a development or a test environment and run a T-SQL code directly. The query looks to me as if you have a problem with invalid data in country names.

    It's also possible to execute T-SQL from X++ through the Connection class, but it's tricky (no compile-time control, bypassing security, the need to handle partitions and data areas explicitly, difficult processing of output and so on) and therefore you generally shouldn't use it. Note that you can achieve something similar with computed columns in views.

  • Community Member Profile Picture
    on at

    Thankyou for the information, I will gladly look those up.

    The reason for executing the query is because the tables has country names in multiple languages, thats why filtering them based on their alphabetic literals. I also found out that we can filter using the following code as well (similar to queryRange):

    QueryBuildRange.value(Global::queryValue(a*..z*));

  • Verified answer
    Martin Dráb Profile Picture
    237,978 Most Valuable Professional on at

    If your intention is filtering by language, use the LanguageId field. Filtering by a-z is very vaguely related to language. For example, if you had Czech translation, your query would include some countries (e.g. Dánsko) but not all (e.g. Čína).

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans