Creating employee records based on user accounts and linking them

When setting up a new system, people tend to spend lots of time setting up the various modules and creating user account. But what is often forgotten is to create employee records and link them to the users.

Below is a quick job that will create employee records for each user account, and link them. This script works on the basis that the user accounts have been allocated to the correct company as their default, and the name is the first and last name of the person. It also can filter out pre-defined users, and users allocated to company DAT, to hopefully get a clean employee set.

This is just for reference and can be adjusted to meet your specific requirements, but is just a simple example how to create employees from user accounts.

static void DAX_CreateEmployeesFromUsers(Args _args)
{
UserInfo UserInfo;
str firstname;
str lastname;
str initials;
str company;
int iemployee;

void CreateUser(str _firstname, str _lastname, str _initials, str _company, str _employeeNo, UserInfo _UserInfo)
{
boolean ret = true;
CompanyInfo companyInfo;
HcmEmploymentRecId newEmploymentRecId;
HcmWorker newHcmWorker;
DirPerson dirPerson;
DirPersonName dirPersonName;
HcmEmploymentType hcmEmploymentType = HcmEmploymentType::Employee;
NumberSeq numberSeqPersonnelNum;
HcmPersonPrivateDetails HcmPersonPrivateDetails;
DirPersonUser DirPersonUser;
;

companyInfo = companyInfo::find();

dirPersonName.FirstName = _firstname;
dirPersonName.LastName = _lastname;
newHcmWorker = HcmWorker::find(HcmWorkerTransition::newCreateHcmWorker(dirPersonName, _employeeNo, companyInfo.RecId));

if (newHcmWorker.RecId == 0)
ret = false;

if (newHcmWorker.RecId == 0)
{
newEmploymentRecId = HcmWorkerTransition::newCreateHcmEmployment(newHcmWorker.RecId, companyInfo.RecId);

if (newEmploymentRecId == 0)
ret = false;
}

if (ret)
{
if(numberSeqPersonnelNum)
numberSeqPersonnelNum.used();
}
else
{
if(numberSeqPersonnelNum)
numberSeqPersonnelNum.abort();

dirPerson.clear();
dirPersonName.Person = 0;
}

hcmPersonPrivateDetails.initValue();
hcmPersonPrivateDetails.Person = dirPersonName.Person;
hcmPersonPrivateDetails.insert();

dirPerson = dirPerson::find(dirPersonName.Person, true);
dirPerson.Initials = _initials;
dirPerson.update();

if(!DirPersonUser::exist(UserInfo.id))
{
DirPersonUser.clear();
DirPersonUser.PersonParty = dirPerson.recid;
DirPersonUser.user = _UserInfo.id;
DirPersonUser.ValidFrom = DateTimeUtil::minValue();
DirPersonUser.ValidTo = DateTimeUtil::maxValue();
DirPersonUser.insert();
}
}

while
select * from UserInfo
order by company, name
where UserInfo.name
{
if(UserInfo.company == ‘DAT’)
continue;

if(UserInfo.name == ‘person1’
|| UserInfo.name == ‘person2’
)
continue;

firstname = ”;
lastname = ”;
initials = ”;
company = ”;

company = strLwr(UserInfo.company);
firstname = strLRTrim(subStr(UserInfo.name, 1, strFind(UserInfo.name, ‘ ‘, 1, 999)-1));
lastname = strLRTrim(subStr(UserInfo.name, strLen(firstname)+1, 999));
initials = subStr(firstname, 1, 1)+subStr(lastname, 1, 1);

info(strFmt(“%1, %2 %3 (%4)”, company, firstname, lastname, initials));

iemployee++;

changeCompany(company)
{
CreateUser(firstname, lastname, initials, company, strRFix(int2str(iemployee), 4, ‘0’), UserInfo);
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s