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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

how to transform select statement to query x++ ?

(0) ShareShare
ReportReport
Posted on by 229

Hi guys,

I'm little confused on how to transform this select statement in query : 

OMOperatingUnit omOpunit;
OMHierarchyRelationship omHierRelation;
DataArea dataReg;
OMInternalOrganization omIO;

str dataarea = '590';

select dataReg where dataReg.id == dataarea;

select omIO where omIO.Name == dataReg.name;

while select omHierRelation where omHierRelation.ParentOrganization == omIO.RecId
{
    select omOpunit
        where omHierRelation.ChildOrganization == omOpunit.RecId;

    Info(omOpunit.Name);
}

I used that in a job and it's working like i want but i need to use it in a lookup eventhandler and its a bit hard for me to find how.

Could someone teach me please ?

Regards.

I have the same question (0)
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    select * from DataArea da
    join OMInternalOrganization omIO on omIO.Name = da.name
    join OMHierarchyRelationship omHierRelation on omHierRelation.ParentOrganization = omIO.RecId
    join OMOperatingUnit omOpunit on omHierRelation.ChildOrganization = omOpunit.RecId
    where dataReg.id = '590';

    You can try this. For me OMInternalOrganization, OMOperatingUnit are not found. Try and let us know.

  • Abhi Profile Picture
    120 on at

    Hi Mack Nate,

    You ask how to create a lookup eventhandler for field.

    Please take the ref this code

    ----------------------------------------------------------------------------------------------------------------

       Query query = new Query();

       QueryBuildDataSource queryBuildDataSource,queryBuildDataSource1;

       QueryBuildRange queryBuildRange;

       SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(PurchTable),this); // this is refer that current ref (In eventhandler sender )

       sysTableLookup.addLookupField(fieldNum(PurchTable, PurchId));

       queryBuildDataSource = query.addDataSource(tableNum(PurchTable));

       querybuilddatasource1 = querybuilddatasource.adddatasource(tablenum(ledgerjournaltrans));

       querybuilddatasource1.addlink(fieldnum(PurchTable, PurchId), fieldnum(ledgerjournaltrans, PurchId));

       queryBuildRange = queryBuildDataSource.addRange(fieldNum(PurchTable, InvoiceAccount));

       queryBuildRange.value(001);

       sysTableLookup.parmQuery(query);

       sysTableLookup.performFormLookup();  

    -------------------------------------------------------------------------------------------------------------------

    Thanks,

  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    Hi, Please check this article and try creating your lookup method. Let us know when you get issues and need assistance.

    daxbeginners.wordpress.com/.../

  • Verified answer
    GirishS Profile Picture
    27,829 Moderator on at

    You can refer to the below query and see if it helps.

    Query query = new query();
    QueryBuildDataSource qbds,qbds1;
    OMOperatingUnit omOpunit;
    OMHierarchyRelationship omHierRelation;
    DataArea dataReg;
    OMInternalOrganization omIO;
    str dataarea = '590';
    
    select dataReg where dataReg.id == dataarea;
    select omIO where omIO.Name == dataReg.name;
    SysTableParameter parameter = new SysTableParameter(tableNUm(OmOperatingUnit),this);
    parameter.addlookupfield(fildnum(OmOperatingUnit, Name));
    qbds = query.addDatasource(tablenum(OmOperatingUnit));
    qbds1 = qbds.addDatasource(tablenum(OmHierarchyRelationship));
    qbds1.addLink(fieldnum(OmOperatingUnit,RecId),fieldnum(OmHierarchyRelationship, ChildOrganisation));
    qbds1.relations(false);
    qbds1.addRange(fieldnum(OmHierarchyRelationship, ParentOrganization)).value(queryvalue(omIo.RecId));
    

    Thanks,

    Girish S.

  • Awaxx Profile Picture
    229 on at

    I did this, its seem to work

           

            Query query = new query();
            QueryBuildDataSource qbds,qbds1;
            OMOperatingUnit omOpunit;
            OMHierarchyRelationship omHierRelation;
            DataArea dataReg;
            OMInternalOrganization omIO;
    
            select dataReg where dataReg.id == ledgJourInfo.DataAreaId;
            select omIO where omIO.Name == dataReg.name;
    
            SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(OMOperatingUnit), location);
            sysTableLookup.addlookupfield(fieldnum(OmOperatingUnit, OMOperatingUnitNumber));
            sysTableLookup.addlookupfield(fieldnum(OmOperatingUnit, Name));
    
    
            qbds = query.addDatasource(tablenum(OmOperatingUnit));
            qbds1 = qbds.addDatasource(tablenum(OmHierarchyRelationship));
            qbds1.addLink(fieldnum(OmOperatingUnit,RecId),fieldnum(OmHierarchyRelationship, ChildOrganization));
            qbds1.relations(false);
            qbds1.addRange(fieldnum(OmHierarchyRelationship, ParentOrganization)).value(queryvalue(omIo.RecId));
    
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();

    Thank you guys.

    Now i need to understand and learn how.

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…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 629 Super User 2025 Season 2

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 444 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 288 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans