Getting Started

Using Automation

Updated: October 22, 2018 Page Information Edit on GitHub

Goal

Leverage Automation and trigger business logic to obtain the contract and all of its attachments as a single PDF file.

Nuxeo University
Watch the related courses on Nuxeo University

Prerequisites

Procedure

  1. Create a file called generateContractWithAttachments.js  with the following content. Be sure to replace the filePath variable with the path to the folder where the PDF file should be downloaded.

    let Nuxeo = require('nuxeo');
    let fs = require('fs');
    let nuxeo = new Nuxeo({
      auth: {
        method: 'basic',
        username: 'sconnor',
        password: 'sconnor'
      }
    });
    
    // Change this value to indicate in which folder the full PDF contract should be downloaded
    // Don't forget the trailing slash
    let filePath = '/tmp/';
    // Which contract to fetch a rendition for
    let contractToFetch = '/default-domain/workspaces/North America/awesome-tech/awesome-contract';
    // Launch the automation chain to generate the final PDF file
    console.log('We\'ll launch an automation chain.');
    console.log('This chain will:');
    console.log('- Gather the contract and all of its attachments');
    console.log('- Convert them to PDF');
    console.log('- And concatenate them all in a single file.');
    nuxeo.operation('BCGenerateCompletePDFContract_ac')
      .input(contractToFetch)
      .execute()
      .then(response => {
        // Download file
        console.log('The file has been generated, we\'ll download it now.');
        try {
          var stats = fs.statSync(filePath);
          if (!stats.isDirectory()) {
            console.log(`${filePath} is is not a folder.\nPlease check the filePath variable (currently set to: ${filepath} )\nand make sure you have the proper rights on that folder.`);
            return;
          }
          const writable = fs.createWriteStream(`${filePath}contract-with-attachments.pdf`);
          response.body.pipe(writable);
          console.log('The complete PDF contract has been downloaded!');
          console.log(`You can take a look at it here: ${filePath}contract-with-attachments.pdf`)
        } catch (error) {
          console.log(`The folder where the rendition should be downloaded cannot be accessed.\nPlease check the filePath variable (currently set to: ${filePath})\nand make sure you have write access on that folder.`);
          console.log(error);
          return;
        }
      })
      .catch(error => {
        console.log('Apologies, an error occurred while generating the final PDF file.');
        console.log(error);
        return;
      });
    
    
  2. Save and run:

    $ node generateContractWithAttachments.js
    

Automation chains allow you to optimize the number of calls needed to execute business logic while maintaining data integrity. All automation chains are executed in a transaction: if the chain fails at some point, it will be rolled back to keep your data safe.

You have now completed this tutorial. To start discovering how to customize the Nuxeo Platform, check the Develop with Nuxeo Platform page.

25 days ago Loubna Benzaama Fix Showcase Content add-on doc
2 years ago Solen Guitter 18
2 years ago Solen Guitter 17
2 years ago Solen Guitter 16
2 years ago Solen Guitter 15
2 years ago Solen Guitter 14
2 years ago Solen Guitter 13
2 years ago Solen Guitter 12
2 years ago Solen Guitter 11
2 years ago Solen Guitter 10
2 years ago Solen Guitter 9
2 years ago Arnaud Kervern 8
2 years ago Solen Guitter 7
2 years ago Solen Guitter 6
2 years ago Bertrand Chauvin 4
2 years ago Bertrand Chauvin 5
2 years ago Bertrand Chauvin 3
2 years ago Bertrand Chauvin 2
2 years ago Bertrand Chauvin 1
History: Created by Bertrand Chauvin

We'd love to hear your thoughts!

All fields required