Wednesday, 30 November 2011

Attach files through code Ax 2012


All,

Following code helps you to attach files.

// AOSRunMode::Client
void attachFile()
{
    Filename            fileName  = @'C:\temp\test.csv';
    DocuRef             tdocuRef;
    DocuRef             updDocuRef;
    DocuType            docuType;      
    HcmWorker           hcmWorker = HcmWorker::findByPersonnelNumber('000466');
    DocuActionArchive   docuActionArchive;  
    ;

    select docutype where docutype.ActionClassId == classNum(DocuActionArchive) &&
       DocuType.TypeId == 'file' ;
   
    tdocuRef.RefRecId       = hcmWorker.RecId;
    tdocuRef.RefTableId     = hcmWorker.TableId;
    tdocuref.RefCompanyId   = 'dat';
    tdocuref.TypeId         = docutype.TypeId;  
    tdocuref.insert();
   
    ttsBegin;  
    select forupdate updDocuRef where updDocuRef.RecId ==  tdocuref.RecId;  
   
    docuActionArchive       = DocuAction::newDocuRef(updDocuRef);  
    docuActionArchive.add(updDocuRef, fileName);
    ttsCommit;  
}

No comments:

Post a Comment