Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

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

Posted on by 170

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

  • Suggested answer
    Hossein.K Profile Picture
    Hossein.K 6,642 on at
    RE: QueryBuildRange in Datasource FORM: How to AND, OR and put NOT LIKE in X++
    qbds1 = this.query().dataSourceTable(tableNum(InventTransOrigin));
    qbrTrans4 = qbds1.addRange(fieldNum(InventTransOrigin, DataAreaId));
    
    qbrTrans4.value(strFmt('((((%1 NOT like *%2*) && %1 NOT like *%3*) || (%4 != %5)) && ((%1 NOT like *%6*) || (%4 != %7))) && ((%1 NOT 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
  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: QueryBuildRange in Datasource FORM: How to AND, OR and put NOT LIKE in X++

    If you have now !(a LIKE b) you should change it to (a NOT like b).

  • JEMT Profile Picture
    JEMT 170 on at
    RE: QueryBuildRange in Datasource FORM: How to AND, OR and put NOT LIKE in X++

    Hi Hossein,

    same position or beside of like?

  • JEMT Profile Picture
    JEMT 170 on at
    RE: QueryBuildRange in Datasource FORM: How to AND, OR and put NOT LIKE in X++

    Hi Nikolaos,

    same position or beside of like?

  • Suggested answer
    Hossein.K Profile Picture
    Hossein.K 6,642 on at
    RE: QueryBuildRange in Datasource FORM: How to AND, OR and put NOT LIKE in X++

    Change the operator to NOT (instead of !)

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: QueryBuildRange in Datasource FORM: How to AND, OR and put NOT LIKE in X++

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

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

  • JEMT Profile Picture
    JEMT 170 on at
    RE: QueryBuildRange in Datasource FORM: How to AND, OR and put NOT LIKE in X++

    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
    Hossein.K Profile Picture
    Hossein.K 6,642 on at
    RE: QueryBuildRange in Datasource FORM: How to AND, OR and put NOT LIKE in X++

    Hi Jhon,

    Do you try my code?

    Can you tell me about what you want?

  • JEMT Profile Picture
    JEMT 170 on at
    RE: QueryBuildRange in Datasource FORM: How to AND, OR and put NOT LIKE in X++

    Hi Hossein,

    No, i did not yet fix

  • Hossein.K Profile Picture
    Hossein.K 6,642 on at
    RE: QueryBuildRange in Datasource FORM: How to AND, OR and put NOT LIKE in X++

    Hi,

    Did you get this issue fixed in the meantime?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans