Create Multiple Employment on Other Companies
Last time, I have to implement AX 2012 in multiple entities customer, and the employee must be made available to all entities. To make the employees available, employment must be made in each entities.
I used below scripts to create another employment to other entities. Employees data must be uploaded and must have employment on one entity (in this case company "B1") as pre-existing condition before running the script. Don't forget to change the value on the "con" variable with the entities (companies) which employment exists.
static void ECL_TI_HCMEmploymentEntityInsert(Args _args)
{
#AviFilesSysOperationProgress progress = new SysOperationProgress();
HcmEmployment employmentSource, employmentTarget;container con = ["A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10", "A11", "A12", "A13"];
int i;
SelectableDataArea companyTarget;
;ttsBegin;
progress.setCaption("Worker Assignment Copy");
progress.setAnimation(#AviUpdate);progress.setTotal(conLen(con));
for(i = 1; i <= conLen(con); i++)
{companyTarget = conPeek(con, i);
progress.setCount(i, 1);
progress.setText(strFmt("Updating on company %1", companyTarget));
while select forUpdate employmentSource where employmentSource.LegalEntity == CompanyInfo::findDataArea("B1").RecId
{//Check if the employment already exists on target entity
select employmentTarget where employmentTarget.Worker == employmentSource.Worker &&
employmentTarget.LegalEntity == CompanyInfo::findDataArea(companyTarget).RecId;if(employmentTarget)
{warning(strFmt("The worker %1 already exists on company %2", employmentSource.Worker, companyTarget));
continue;
}
employmentTarget.clear();
employmentTarget.initValue();
employmentTarget.LegalEntity = CompanyInfo::findDataArea(companyTarget).RecId;
employmentTarget.EmploymentType = employmentSource.EmploymentType;
employmentTarget.DefaultDimension = employmentSource.DefaultDimension;
employmentTarget.EEOEstablishment = employmentSource.EEOEstablishment;
employmentTarget.ValidFrom = employmentSource.ValidFrom;
employmentTarget.ValidTo = employmentSource.ValidTo;
employmenttarget.Worker = employmentSource.Worker;
employmentTarget.insert();
}info(strFmt("Company %1 - done",companyTarget));
}ttsCommit;
}
{
#AviFilesSysOperationProgress progress = new SysOperationProgress();
HcmEmployment employmentSource, employmentTarget;container con = ["A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10", "A11", "A12", "A13"];
int i;
SelectableDataArea companyTarget;
;ttsBegin;
progress.setCaption("Worker Assignment Copy");
progress.setAnimation(#AviUpdate);progress.setTotal(conLen(con));
for(i = 1; i <= conLen(con); i++)
{companyTarget = conPeek(con, i);
progress.setCount(i, 1);
progress.setText(strFmt("Updating on company %1", companyTarget));
while select forUpdate employmentSource where employmentSource.LegalEntity == CompanyInfo::findDataArea("B1").RecId
{//Check if the employment already exists on target entity
select employmentTarget where employmentTarget.Worker == employmentSource.Worker &&
employmentTarget.LegalEntity == CompanyInfo::findDataArea(companyTarget).RecId;if(employmentTarget)
{warning(strFmt("The worker %1 already exists on company %2", employmentSource.Worker, companyTarget));
continue;
}
employmentTarget.clear();
employmentTarget.initValue();
employmentTarget.LegalEntity = CompanyInfo::findDataArea(companyTarget).RecId;
employmentTarget.EmploymentType = employmentSource.EmploymentType;
employmentTarget.DefaultDimension = employmentSource.DefaultDimension;
employmentTarget.EEOEstablishment = employmentSource.EEOEstablishment;
employmentTarget.ValidFrom = employmentSource.ValidFrom;
employmentTarget.ValidTo = employmentSource.ValidTo;
employmenttarget.Worker = employmentSource.Worker;
employmentTarget.insert();
}info(strFmt("Company %1 - done",companyTarget));
}ttsCommit;
}
Comments
Post a Comment