根据 Personnelnumber 更新 HCMWorker RecId 字段

Update HCMWorker RecId field based on Personnelnumber

我收到了一个 CSV 文件,其中提供了一个 SalesQuotationId 和一个 Personnelnumber,我创建了一个作业以通过 find 方法查找 SalesQuotation。

在 SalesQuotationTable 上,我有一个字段,与 HCMWorkerRecId 一起存储。问题是,我在 CSV 文件中只有人员编号。我找不到如何根据 PersonnelNumber 更改 HCMWorker 的 RecId。

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!");
        }
    }

您可以在 HcmWorker[=18] 上使用静态函数 findByPersonnelNumber 通过 PersonnelNumber 找到 HcmWorker 记录=] table。只需将 salesQuotationTable.WorkerField = worker; 替换为

salesQuotationTable.WorkerField = HcmWorker::findByPersonnelNumber(worker).RecId;