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 :

How to get user's stores in AX

Muhammad Yasir Profile Picture Muhammad Yasir 1,023
Hi,

Today i will show you how to get all the stores that are assigned to a particular user in AX. We usually have a requirement of displaying all the stores that are related to a particular user.so after a little bit research i came across this simple solution.

It's not a big deal, just use the below mentioned code and use it where ever you want.

QueryBuildDataSource    qbds, storeAddresssBookDS, dirAddressBookPartyDS;
Query                              query = new query();
QueryRun                        qr ;
RetailStoreTable              RetailStoreTable;

qbds = query.addDataSource(tableNum(RetailStoreTable));
storeAddresssBookDS = qbds.addDataSource(tableNum(RetailStoreAddressBook));
storeAddresssBookDS.relations(true);
storeAddresssBookDS.addRange(fieldNum(RetailStoreAddressBook,AddressBookType)). value(enum2str(RetailAddressBookType::Employee));
storeAddresssBookDS.fetchMode(QueryFetchMode::One2One);
storeAddresssBookDS.joinMode(JoinMode::ExistsJoin);

dirAddressBookPartyDS = storeAddresssBookDS.addDataSource(tableNum(DirAddressBookParty));
dirAddressBookPartyDS.addLink(fieldNum(RetailStoreAddressBook,AddressBook),fieldNum(DirAddressBookParty,AddressBook));
dirAddressBookPartyDS.addRange(fieldNum(DirAddressBookParty,Party)).value(SysQuery::value (HcmWorker::findByPersonnelNumber("000137").Person)); // for particular user having id "000137"
dirAddressBookPartyDS.fetchMode(QueryFetchMode::One2One);

qr = new QueryRun(query);
 while (qr.next())
 {
        RetailStoreTable =  qr.get(tableNum(RetailStoreTable));
        info(RetailStoreTable.StoreNumber + "("+RetailStoreTable.name()+")");
 }

// can use this if we want to dsipaly the stores of currently login user
DirPersonUser::currentWorkerPersonnelNumber()


Enjoy DAXing



This was originally posted here.

Comments

*This post is locked for comments