Getting Started

Using Automation

Updated: November 29, 2017 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.

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.

Learn more

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

11 days ago manonlumeau Update NX University links with Docebo URLs
a month ago manonlumeau Added content-review-lts2017 label
2 months ago manonlumeau NXDOC-1346-FT review screenshot
a year ago Solen Guitter 18
a year ago Solen Guitter 17
a year ago Solen Guitter 16
a year ago Solen Guitter 15
a year ago Solen Guitter 14
a year ago Solen Guitter 13
a year ago Solen Guitter 12
a year ago Solen Guitter 11
a year ago Solen Guitter 10
a year ago Solen Guitter 9
a year ago Arnaud Kervern 8
a year ago Solen Guitter 7
a year ago Solen Guitter 6
a year ago Bertrand Chauvin 4
a year ago Bertrand Chauvin 5
a year ago Bertrand Chauvin 3
a year ago Bertrand Chauvin 2
a year ago Bertrand Chauvin 1
History: Created by Bertrand Chauvin