2017-03-02 7 views
0

SalesQuotationId 및 Personnelnumber를 제공하는 CSV 파일을 받았으므로 find 메서드를 통해 SalesQuotation을 찾을 수있는 작업을 만들었습니다.Personnelnumber를 기준으로 HCMWorker RecId 필드 업데이트

SalesQuotationTable에는 RecIdHCMWorker으로 저장된 필드가 있습니다. 문제는 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!"); 
     } 
    } 

답변

1

당신은 HcmWorker 테이블에 정적 기능 findByPersonnelNumber를 사용 PersonnelNumber에 의해 HcmWorker 기록을 찾을 수 있습니다. 그냥 salesQuotationTable.WorkerField = worker;

salesQuotationTable.WorkerField = HcmWorker::findByPersonnelNumber(worker).RecId; 
으로 바꿉니다.