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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

QueryBuildRange in Datasource FORM: How to AND, OR and put NOT LIKE in X++

(0) ShareShare
ReportReport
Posted on by 178

Hi Experts,

Need some help.

I customize a form that can view the some records but i want to remove some of it.

How to translate this SQL Query to X++ Codes (Query).

select * from INVENTTRANSORIGIN
where ((((REFERENCEID not like '%INF-SO%' and REFERENCEID not like '%CLA-SO%' ) 
	or (DATAAREAID != 'wiz')) 
	and ((REFERENCEID not like '%INF-PO%') or (DATAAREAID != 'inf'))) 
	and ((REFERENCEID not like '%CLA-PO%') or (DATAAREAID != 'cla')))
public void init()
{
    super();
    
    qbdsTrans = this.query().dataSourceTable(tableNum(InventTransOrigin));
    
}
public void executeQuery()
{

  qbrDataAreaId = qbdsTrans.addRange(fieldNum(InventTransOrigin, DataAreaId));
  
    super();
}

Thanks & Regards,

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Hossein.K Profile Picture
    6,648 on at
  • JEMT Profile Picture
    178 on at

    Hi Hossein,

    Thanks for the reply you link is useful. I know that query syntax in X++

    but how about in Datasource form (init and executequery) ?

    Thanks.

  • Community Member Profile Picture
    on at

    Hi Jhon Edmar Tarlac ,

    Here is the tutorial of Expressions in query ranges:www.axaptapedia.com/Expressions_in_query_ranges

    Best Regards

    Tom Cai

  • Suggested answer
    Hossein.K Profile Picture
    6,648 on at

    X++ code is this:

    INVENTTRANSORIGIN iNVENTTRANSORIGIN;
    select * from iNVENTTRANSORIGIN
    where 
          (((!(iNVENTTRANSORIGIN.REFERENCEID like '*INF-SO*') &&!iNVENTTRANSORIGIN.REFERENCEID like '*CLA-SO*' ) 
    	|| (iNVENTTRANSORIGIN.DATAAREAID != 'wiz')) 
    	&&(!(iNVENTTRANSORIGIN.REFERENCEID like '*INF-PO*') || (iNVENTTRANSORIGIN.DATAAREAID != 'inf'))) 
    	&&(!(iNVENTTRANSORIGIN.REFERENCEID like '*CLA-PO*') || (iNVENTTRANSORIGIN.DATAAREAID != 'cla')))


  • JEMT Profile Picture
    178 on at

    Hi Tom,

    Yean i already check that page and i tried this code below.

    qbds1 = this.query().dataSourceTable(tableNum(InventTransOrigin));
    qbrTrans4 = qbds1.addRange(fieldNum(InventTransOrigin, DataAreaId));
    
    qbrTrans4.value(strFmt('(((!(%1 like *%2*) && !%1 like *%3*) || (%4 != %5)) && (!(%1 like *%6*) || (%4 != %7))) && (!(%1 like *%8*) || (%4 != %9)))',
                                fieldNum(InventTransOrigin, ReferenceId), //%1
                                queryValue('INF-SO'), // %2
                                queryValue('CLA-SO'), // %3
                                fieldNum(InventTransOrigin, DataAreaId), //%4
                                queryValue('wiz'), // %5
                                queryValue('INF-PO'), //%6
                                queryValue('inf'), //%7
                                queryValue('CLA-PO'), //%8
                                queryValue('cla'))); //%8
    


    but i got error.

    Query extended range failure: The '!' operator can only be used with the 'like' keyword.


  • Hossein.K Profile Picture
    6,648 on at

    Hi,

    Did you get this issue fixed in the meantime?

  • JEMT Profile Picture
    178 on at

    Hi Hossein,

    No, i did not yet fix

  • Suggested answer
    Hossein.K Profile Picture
    6,648 on at

    Hi Jhon,

    Do you try my code?

    Can you tell me about what you want?

  • JEMT Profile Picture
    178 on at

    Hi Hossein,

    I did not try your code because i already do that using JOB but what i want to achieve now by using QueryBuildDatasource and Range in the Form and Datasource.

    I already share above the code i tried and the error.

    Can you please check my code above? it seems like i missing something...

    Thanks in advance.

  • Suggested answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    Regarding your error message "the '!' operator can only be used with the 'like' keyword." 

    Try using "NOT LIKE" instead of the ! mark.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 16

#2
GiacomoRovai Profile Picture

GiacomoRovai 4

#3
Douglas Noel Profile Picture

Douglas Noel 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans