Add document to record

Simple code snippet to add a document attachment to a 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)
        {
            //after ttsCommit to enable catching of file system errors
            DocuValue::writeDocuValue(docuRef,filename);
        }
    }
}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *