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
How to get user's stores in AX
Views (761)
This was originally posted here.

Like
Report
*This post is locked for comments