Update worker Default Dimensions
static void updateWorkerDIm(Args _args)
{
#File
Dialog dialog;
Filename filename;
DialogField dialogFilename;
DataAreaId companyCode;
HcmWorker hcmWorker;
HcmEmployment hcmEmployment;
HcmPersonnelNumberId hcmRecId;
container ledgerdimensionheader;
DimensionDefault dimensiondefaultheader;
Struct structHdr = new Struct();
boolean first = true;
//To filter the files while selecting
container conFilter = ["Comma Seperated Value .txt ", "*.csv"];
IO iO;
FilenameOpen filenameOpen;
Container record;
dialog = new dialog();
dialog.caption("Select File to update workers");
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
//To filter the files while selecting
dialog.filenameLookupFilter(conFilter);
dialog.run();
if(dialog.closedOk())
{
filename = dialogFileName.value();
}
iO = new CommaTextIo(filename,#IO_Read);
if (! iO || iO.status() != IO_Status::Ok)
{
throw error("@SYS19358");
}
try
{
ttsBegin;
while (iO.status() == IO_Status::Ok)
{
record = iO.read();// To read file
if (record)
{
if (first) //To skip header
{
first = false;
}
else
{
hcmRecId = conpeek(record, 1);
hcmWorker = HcmWorker::findByPersonnelNumber(hcmRecId);
while select forUpdate hcmEmployment order by RecId asc where hcmEmployment.Worker == hcmWorker.RecId
//&& hcmEmployment.EmploymentType != 1
{
structHdr.remove('Worker');
structHdr.add('Worker', hcmWorker.PersonnelNumber);
ledgerDimensionHeader += structHdr.fields();
ledgerDimensionHeader += structHdr.fieldName(1);
ledgerDimensionHeader += structHdr.valueIndex(1);
dimensionDefaultHeader = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimensionHeader);
hcmEmployment.DefaultDimension = dimensionDefaultHeader;
hcmEmployment.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
hcmEmployment.update();
ledgerDimensionHeader = conDel(ledgerDimensionHeader,1,30);
}
}
}
}
info('Imported successfully');
ttsCommit;
}
catch(Exception::Error)
{
error('An Exception has occurred');
}
}
static void updateWorkerDIm(Args _args)
{
#File
Dialog dialog;
Filename filename;
DialogField dialogFilename;
DataAreaId companyCode;
HcmWorker hcmWorker;
HcmEmployment hcmEmployment;
HcmPersonnelNumberId hcmRecId;
container ledgerdimensionheader;
DimensionDefault dimensiondefaultheader;
Struct structHdr = new Struct();
boolean first = true;
//To filter the files while selecting
container conFilter = ["Comma Seperated Value .txt ", "*.csv"];
IO iO;
FilenameOpen filenameOpen;
Container record;
dialog = new dialog();
dialog.caption("Select File to update workers");
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
//To filter the files while selecting
dialog.filenameLookupFilter(conFilter);
dialog.run();
if(dialog.closedOk())
{
filename = dialogFileName.value();
}
iO = new CommaTextIo(filename,#IO_Read);
if (! iO || iO.status() != IO_Status::Ok)
{
throw error("@SYS19358");
}
try
{
ttsBegin;
while (iO.status() == IO_Status::Ok)
{
record = iO.read();// To read file
if (record)
{
if (first) //To skip header
{
first = false;
}
else
{
hcmRecId = conpeek(record, 1);
hcmWorker = HcmWorker::findByPersonnelNumber(hcmRecId);
while select forUpdate hcmEmployment order by RecId asc where hcmEmployment.Worker == hcmWorker.RecId
//&& hcmEmployment.EmploymentType != 1
{
structHdr.remove('Worker');
structHdr.add('Worker', hcmWorker.PersonnelNumber);
ledgerDimensionHeader += structHdr.fields();
ledgerDimensionHeader += structHdr.fieldName(1);
ledgerDimensionHeader += structHdr.valueIndex(1);
dimensionDefaultHeader = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimensionHeader);
hcmEmployment.DefaultDimension = dimensionDefaultHeader;
hcmEmployment.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
hcmEmployment.update();
ledgerDimensionHeader = conDel(ledgerDimensionHeader,1,30);
}
}
}
}
info('Imported successfully');
ttsCommit;
}
catch(Exception::Error)
{
error('An Exception has occurred');
}
}