attachFile

Posted by Alvin You
2013. 11. 13. 15:06 카테고리 없음

public static void attachFile(Common     _recordToAttachTo,
                              Str        _attachFile,
                              DocuTypeId _typeId)
{

    //rvbAttachDoc::attachFile(salesTable, fcFileName, 'File');

    DocuActionArchive   docuActionArchive   ;
    DocuActionFile      docuActionFile      ;
    DocuAction          docuAction          ;
    DocuRef             docuRef             ;
    DocuType            docuType            ;

    docuType = DocuType::find(_typeId) ;
    if(! docuType.RecId)
    {
        throw Error (strFmt(strFmt("Document Type %1 not setup in document handling.", _typeId)));
    }else
    {
        if (docuType.ActionClassId != ClassNum(DocuActionArchive) ||
            docuType.TypeGroup     != DocuTypeGroup::File)
        {
            throw Error(strFmt("Class Description should be 'Attach File' and Group should be 'File' for Document Type %1", _typeId));
        }
    }

    ttsBegin;
    docuRef.ActualCompanyId     =   curExt()                    ;
    docuRef.Name                =   'Automatically Attached'    ;
    docuRef.Notes               =   'Automatically Attached'    ;
    docuRef.RefCompanyId        =   curExt()                    ;
    docuRef.RefRecId            =   _recordToAttachTo.RecId     ;
    docuRef.RefTableId          =   _recordToAttachTo.TableId   ;
    docuRef.Restriction         =   DocuRestriction::Internal   ;
    docuRef.TypeId              =   'File'                      ;
    docuRef.insert()    ;

    docuActionArchive = new docuActionArchive() ;
    docuActionArchive.add(docuRef, _attachFile) ;

    ttsCommit;
}