How to associate a worker with user ID using X++ and add External Relation

Hi all,

I need assistance to associate an AX user with a person (Vendor Contact that I have already created) using x++ and then assign an External Vendor relation so the Vendor contact person can access AX through enterprise portal. Data sources on user relations form (System admin-> User relations → new) shows: DirpersonUser.PersonParty, UserExternalParty, and UserInfo. I wonder if anyone can assist?


Well I figured it out how to do it. you need to have the User info and contact person and then insert into tables… something like this:

DirPersonUser dirPersonUser ;

DirPerson dirPerson;

DirPersonUser.PersonParty = DirPerson.RecId;
DirPersonUser.User = “UsertoBeAssociated”;
DirPersonUser.ValidTo = ;
DirPersonUser.ValidFrom = ;

… and


UserExternalParty.LegalEntity = CompanyInfo::current();
UserExternalParty.User = “UsertoBeAssociatedExternalRole”;
UserExternalParty.ExternalParty = DirPerson.RecId; ;

UserExternalParty.ExternalEntityType = UserExternalPartyEntityType::Vendor;

The code you used is great for external relation, but I needed just the internal. For that you only need DirPersonUser:

DirPersonUser PersonUser;


PersonUser.PersonParty = DirPerson.RecID;

PersonUser.User =;

PersonUser.ValidFrom = DateTimeUtil::getSystemDateTime();

PersonUser.ValidTo = DateTimeUtil::maxValue();