EmplTable::find(emplId).email;
I needed to get the Employee ID for a custom functionality that sends a sales status confirmation email to a contact with copy to the employee that is handling that Sales Order.
In Microsot Dynamics AX 2009, however, the employee's information is handled diferently. For example, the Employee contact information is stored in a table called DirECommunicationAddress, and the Employee's address is stored in the Address table.
If you were to look at the DirECommunicationAddress data, you will see that there is not any logical relationship between the employee ID, PartyID or even a Record Id between the EmplTable and the DirECommunicationAddress table.
For more info about the tables mentioned above see the following:
EmplTable: http://msdn.microsoft.com/en-us/library/aa604174.aspx
DirECommunicationAddress: http://msdn.microsoft.com/en-us/library/cc602485.aspx
Address: http://msdn.microsoft.com/en-us/library/aa643886.aspx
Well, it turns out that thereare a couple of tables in the AOTcalled SysCompanyUserInfo and SysUserInfo.
The SysCompanyUserInfo Table stores data such as the EmplId, PartyId and UserId (the same that it is assigned when you create a new user in AX).
The SysUserInfo table stores data such as the Userid, email, ect.
SysCompanyUserInfo : http://msdn.microsoft.com/en-us/library/aa652494.aspx
SysUserInfo: http://msdn.microsoft.com/en-us/library/aa846971.aspx
So, how can I get the Employee email then?
public Email GetEmployeeEmailFromEmplId(EmplId emplId)
{
Email email;
UserId userId;
;
if(!emplId)
return '';
userId = SysCompanyUserInfo::emplId2UserId(emplId);
email = SysUserInfo::find(userId, false).Email;
return email;
}
The above method takes the EmplId as a parameter and uses the SysCompanyUserInfo emplId2UserId native method to give me the UserId out of the EmplId. Cool, isn't?
Then I assign the email from SysUserInfo to my email variable.
No comments:
Post a Comment
Thank you for your thoughts. Your comment will appear in my blog shortly after review.
Have a great day!