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?

Thanks.

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 = ;
DirPersonUser.insert();

… and

CompanyInfo::current();

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

UserExternalParty.ExternalEntityType = UserExternalPartyEntityType::Vendor;
UserExternalParty.insert();

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

DirPersonUser PersonUser;

PersonUser.clear();

PersonUser.PersonParty = DirPerson.RecID;

PersonUser.User = UserInfo.id;

PersonUser.ValidFrom = DateTimeUtil::getSystemDateTime();

PersonUser.ValidTo = DateTimeUtil::maxValue();

PersonUser.insert();