How to Debug Process and Document Properties using Groovy

Document created by Adam Arrowsmith Employee on Oct 26, 2011Last modified by Adam Arrowsmith Employee on Sep 25, 2017
Version 3Show Document
  • View in full screen mode

This article provides a Groovy script that can be used during development to help troubleshoot and debug processes by outputting the current values of document and process properties at a given point in the process.

 

 Get the example process used below from the Process Library here.

 

 

Use Case

This script provides visibility to the current values of all Process and Document Properties and can be useful for developing and debugging processes that use properties extensively.

 

Implementation

The script consolidates all the Process and Document Properties from one or more incoming documents and outputs a single document. This resulting document can be written to disk or the Process Log for further analysis.

 

Note: It is intended for low volume, debugging scenarios and is not recommended for high volume or production use.

 

Script

 

// Debug script that dumps the current Document and Process Properties to a document.

import com.boomi.execution.ExecutionManager;

NEWLINE = System.getProperty("line.separator");
StringBuilder sb = new StringBuilder();

// Get all process properties
execProps = ExecutionManager.getCurrent().getProperties();
sb.append("PROCESS PROPERTIES: " + NEWLINE);
formatProps(sb, execProps);
sb.append(NEWLINE);
outputDocProps = null;

for( int i = 0; i < dataContext.getDataCount(); i++ ) {
  InputStream is = dataContext.getStream(i);
  Properties props = dataContext.getProperties(i);

  if (i==0) outputDocProps = props;
    sb.append("DOCUMENT " + i + " PROPERTIES: " + NEWLINE);

formatProps(sb, props);
sb.append(NEWLINE);
}

// Output single document with props
is = new ByteArrayInputStream(sb.toString().getBytes());
dataContext.storeStream(is, outputDocProps);

def formatProps(sb, props) {
  for (k in props.keySet()) {
    sb.append(k + "=" + props.get(k) + NEWLINE);
  }
}

 

Using it in a Process

To easily add to any process, you may wish to use this script in a "subprocess" that can be referenced by other processes. Here's an example of a subprocess that uses the script but still passes the source document straight through so the Process Call step can be made "inline".

 

 

7 people found this helpful

Attachments

    Outcomes