I have received an CSV file which provides me a SalesQuotationId and a Personnelnumber, I have created a Job to find the SalesQuotation via the find
method.
On the SalesQuotationTable I have a field, stored with the RecId
of the HCMWorker
. The problem is, I only have the Personnel number in the CSV file. I can't find out how to change the RecId of the HCMWorker based on the PersonnelNumber.
static void UpdateHCMWorkerField(Args _args)
{
#File
CommaTextIo inFile;
Container con;
int i;
FileIOPermission permission;
FilePath readFile;
SalesQuotationTable salesQuotationTable;
SalesQuotationId quotationId;
str worker;
HcmWorker hcmWorker;
;
readFile = "File.csv";
permission = new FileIOPermission(readFile, #io_read);
permission.assert();
inFile = new CommaTextIo(readFile, #io_read);
inFile.inFieldDelimiter(",");
while (inFile.status() == IO_Status::Ok)
{
con = inFile.read();
quotationId = conPeek(con,1);
worker = conPeek(con,2);
salesQuotationTable = salesQuotationTable::find(quotationId,true);
if(salesQuotationTable && worker) {
ttsBegin;
// Obviously, this is not working working because I am trying to update the RecId field with a string value.
salesQuotationTable.WorkerField = worker;
salesQuotationTable.update();
ttscommit;
}
info("Done!");
}
}
You can find HcmWorker record by PersonnelNumber using static function findByPersonnelNumber
on HcmWorker table. Just replace salesQuotationTable.WorkerField = worker;
with
salesQuotationTable.WorkerField = HcmWorker::findByPersonnelNumber(worker).RecId;