Document Helper Service

To simplify working with document objects there is a helper service avilable called DocumentHelperService.

Via this service you can for example do operations like:

  • Create new document and connect to a parent object

  • Upload local file content into a document

  • Upload new file version

  • Get derived output

Example how to create and connect a new document

const service = context.dsxAPI().getDocumentHelperService();
const docInfo = service.createConnectDocument({
    type: 'The Type',
    title: 'Document Title',
    description: '...'
}, {
    id: 'id of parent object',
    rel: 'Name of Rel Type',
    'direction' : 'from'
});

Example: How to Upload Content from a Local File

const file = context.localFileAPI().create('foo.txt');
// add content to file...
const service = context.dsxAPI().getDocumentHelperService();
service.uploadNew(file, documentId, 'foo.txt', 'checkin comment');

Example: Download File Content

const service = context.dsxAPI().getDocumentHelperService();
const file = service.download(documentId, fileId, false); // last arg = lock object or not
// do something with 'file'

Example: Create a new File Version

    const service = context.dsxAPI().getDocumentHelperService();
    const file = context.localFileAPI().create('filename.txt');
    service.uploadFileVersion(file, /* required */
            documentId,             /* required */
            fileId,                 /* optional: if null, extra query is made to figure out */
            checkinFileName,        /* optional: if null, name of file is used */
            checkinComments,        /* optional */
            false                   /* keep-locked */
    );

Example: Get Derived Output

    const service = context.dsxAPI().getDocumentHelperService();
    const files = service.getDerivedOutput(objectId);
    // NOTE: files is a collection/array of (local) files