Skip to main content
· 1 min read

Get Sales Representative Personnel Number from Store Number

Retrieve the sales representative personnel number from a store number using X++ in D365 Finance and Operations.

A

Ahmad Hassan

Dynamics 365 F&O Consultant

Share
Get Sales Representative Personnel Number from Store Number

This X++ method retrieves the personnel number of the sales representative associated with a specified retail store. It identifies the related RetailStoreTable and RetailChannelTable records, then follows the store address book and party relationship to locate the corresponding HcmWorker. The method returns the worker's PersonnelNumber.

X++ Code

public static Name getSalesrep(str _storeNum)

{

    RetailStoreTable        retailStoreTable;

    HcmWorker               hcmWorker;

    RetailChannelTable      retailChannelTable;

    RetailStoreAddressBook  retailStoreAddressBook;

    DirAddressBookParty     dirAddressBookParty;

    str                     personalNum;

    select firstonly retailStoreTable

        join retailChannelTable

        where retailChannelTable.RecId     == retailStoreTable.RecId

           && retailStoreTable.StoreNumber == _storeNum

        join retailStoreAddressBook

        where retailChannelTable.RecId == retailStoreAddressBook.StoreRecId

        join dirAddressBookParty

        where dirAddressBookParty.AddressBook  == retailStoreAddressBook.AddressBook

        join hcmWorker

        where hcmWorker.Person == dirAddressBookParty.Party;

    {

        personalNum = hcmWorker.PersonnelNumber;

    }

    return personalNum;

}

Process Flow


  1. The method receives the retail store number through _storeNum and selects the matching RetailStoreTable record.


  2. It joins RetailChannelTable, RetailStoreAddressBook, and DirAddressBookParty to follow the store's address book and party relationships.


  3. The related HcmWorker is identified through the party relationship.


  4. The worker's PersonnelNumber is assigned to personalNum and returned.

    00e3c2b4-8792-45d6-b620-b0fc044cc6fc.png

Figure: Flow of retrieving the sales representative personnel number from a retail store.

Found this useful?

Share it with your network

A

Written by

Ahmad Hassan

Microsoft Dynamics 365 Finance & Operation, Technical Consultant

More about me

Comments

Leave a comment