ax 2012 de insan kaynakları yada borax ta personel bilgilerini (kimlik bilgileri, banka bilgileri vs..) güncellemek yada sıfırdan (excel, csv..) import etme ihtiyacını duyabiliriz. umarım bu paylaşım faydalı olur.
önce Erd diyagramı paylaşayım.
https://www.microsoft.com/dynamics/ax/erd/ax2012r2/Erd-One-HumanRes-HR1-HcmBenefits.htm
bu job değiştirilerek insert yada parçalı update yapılabilir, aynı zamanda işlem yapılan kayıtları txt dosyasınada yazar.
static void
ckr_Hr_boraxUpdImport(Args _args)
{SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row;
FileName filename;
Dialog dialog;dialogfield dfile;
BorAXEmplTable
_boraxEmplTable;
BoraxEmplId
_boraxEmplId;HcmWorker _hcmWorker;
HcmPersonnelNumberId _hcmPersonnelNumberId;
DirPerson _dirPerson;
DirPersonName _dirPersonName;
DirPartyTable _dirPartyTable;
// txt
TextIO file;container line;
#define.filename('c:\\personelimport.txt')
#File//
;
file = new TextIO(#filename, 'W+');
if (!file || file.status() != IO_Status::Ok)
{
throw error("File cannot be opened.");
}
//txt
application =
SysExcelApplication::construct();
workbooks =
application.workbooks();Dialog = new dialog("Dosya seçin");
dfile = dialog.addField(extendedTypeStr(FileNameOpen),"Dosya");
if(!dialog.run())
return;filename = dfile.value();
if( filename == "" )
throw error("Dosya adı belirtilmemiş");
try
{workbooks.open(filename);
}
catch (Exception::Error)
{throw error("File cannot be opened.");
}
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
row++;
try
{ttsbegin;
do
{
row++;
_hcmPersonnelNumberId = cells.item(row, 1).value().bStr();
_boraxEmplTable.clear();
select forUpdate
_boraxEmplTable where
_boraxEmplTable.EmplId == _hcmPersonnelNumberId;//cells.item(row,
1).value().bStr();
if (_boraxEmplTable)
{_boraxEmplTable.PersonnelNumber = cells.item(row, 2).value().bStr();
_boraxEmplTable.OldEmplId = cells.item(row, 2).value().bStr();
_boraxEmplTable.EmplId = cells.item(row, 3).value().bStr();
_boraxEmplTable.EmplName = cells.item(row, 4).value().bStr();
_boraxEmplTable.StartDate = cells.item(row, 5).value().date();
_boraxEmplTable.EndDate= cells.item(row, 6).value().date();
_boraxEmplTable.TCIDNumber = cells.item(row, 7).value().bStr();
_boraxEmplTable.update();
if (_hcmWorker)
{_hcmWorker.PersonnelNumber = cells.item(row, 2).value().bStr();
_hcmWorker.update();
_dirPersonName = dirPersonName::find(_hcmWorker.Person, true);
if (_dirPersonName)
{_dirPersonName.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
_dirPersonName.FirstName = cells.item(row, 2).value().bStr();
_dirPersonName.MiddleName = cells.item(row, 3).value().bStr();
_dirPersonName.LastName= cells.item(row, 4).value().bStr();
_dirPersonName.update();
}// txt dosyaya yaz başla
file.outFieldDelimiter(';');// for semicolon seperator
line = [_hcmPersonnelNumberId,cells.item(row, 4).value().bStr(),cells.item(row, 5).value().date(), cells.item(row, 6).value().date(),
cells.item(row, 7).value().bStr()];
file.writeExp(line);
//txt bitir
}
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
ttscommit;info("işlem başarıyla tamamlandı. hadi hayırlı olsun.");
}
catch
{info(strFmt(" Personel Hesabı : %1 ",cells.item(row, 1).value().bStr()));
info("işlem sırsaında bir hata oluştu :(");
}
application.quit();
}

