Friday 18 March 2016

Add Document Attachment to the record

static void addDoc( Common common,
                    DocuTypeId docuTypeId,
                    FileName fileName)
{
    DocuRef docuRef;
    DocuValue docuValue;
 
    if(common && docuTypeId)
    {
        ttsBegin;
        docuRef.clear();
        docuRef.initValue();
        docuRef.TypeId = docuTypeId;
        docuRef.Name = filename;
        docuRef.RefRecId = common.RecId;
        docuRef.RefTableId = common.TableId;
        docuRef.RefCompanyId = curext();
        docuValue.initFromDocuRef(docuRef);
        docuValue.insert();
        docuRef.ValueRecId = docuValue.RecId;
        docuRef.insert();
        ttsCommit;
        if(filename)
        {
            DocuValue::writeDocuValue(docuRef,filename); //after ttsCommit to enable catching of file system errors
        }
    }
}

No comments:

Post a Comment