static void Krishh_ImportCostCenterOwner(Args _args)
{
#File
#AviFiles
#OCCRetryCount
Dialog dialog = new dialog("Import cost center owners");
DialogField dlgFileNameOpen, dlgFirstRowsIsHeader;
Filename fileName;
NoYesId firstRowIsHeader;
container readcon;
CommaIO file;
FileIoPermission permission;
SysOperationProgress progressbar = new SysOperationProgress();
Counter fileRowsRead;
OMOperatingUnit oMOperatingUnit;
DimensionAttribute dimensionAttributeValue;
HcmWorkerRecId hcmWorkerRecId;
dlgFileNameOpen = dialog.addField(extendedTypeStr(FilenameOpen));
dlgFirstRowsIsHeader = dialog.addField(extendedTypeStr(NoYesId), "First row is header");
if (dialog.run())
{
fileName = dlgFileNameOpen.value();
firstRowIsHeader = dlgFirstRowsIsHeader.value();
if (!fileName)
throw error("File name must be specified");
permission = new FileIoPermission(filename,'r');
permission.assert();
file = new CommaIo(filename, 'r');
file.inFieldDelimiter(';');
if (!file)
throw error(strFmt("Error opening file", fileName));
progressbar.setCaption("Importing cost center owners");
progressbar.setAnimation(#AviUpdate);
try
{
ttsBegin;
while (file.status() == IO_Status::OK)
{
readCon = file.read();
fileRowsRead++;
if (fileRowsRead > firstRowIsHeader && readCon && conPeek(readcon, 1))
{
oMOperatingUnit = OMOperatingUnit::findName(conPeek(readcon, 1), OMOperatingUnitType::OMCostCenter);
if (!oMOperatingUnit)
warning(strFmt("Cost center %1 not found."));
else
{
// Find worker from user id
hcmWorkerRecId = HcmWorker::userId2Worker(conPeek(readcon, 2));
if (!hcmWorkerRecId)
warning(strFmt("User id %1 not found as worker in AX."));
else
{
// Find and update dimensionAttributeValue with worker as owner
}
}
}
progressbar.setText(strfmt("@SYS136776", fileRowsRead));
progressbar.update();
}
ttsCommit;
info(strFmt("%1 rows read from file", fileRowsRead));
}
catch (Exception::Error)
{
error("Error");
}
catch (Exception::Deadlock)
{
retry;
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
}
}
No comments:
Post a Comment
Thanks for visiting my blog,
I will reply for your comment within 48 hours.
Thanks,
krishna.