Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

On this Page

Table of Contents
excludeOlder Versions|Additional Resources|Related Links|Related Information


This Snap is Deprecated. See Script instead.

Snap type:Write

This Snap executes a script file using the ScriptEngine mechanism. The script is contained within a file, which can be located anywhere SnapLogic and the SnapLogic user has access to it.

Support and limitations:

Works in Ultra Task Pipelines if you pass the original document to the 'write()' method for the output view. For example, in the JavaScript template, the body of the loop looks like:

Code Block
// Read the next document, wrap it in a map and write out the wrapper
   var doc =;
   var wrapper = new java.util.HashMap();
   wrapper.put("original", doc);

The last line should look like:

Code Block
this.output.write(doc, wrapper);

The original document is needed so that lineage can be maintained.

Multiexcerpt include macro
pageAugust 2020, 4.22 Release Notes


Accounts are not used with this Snap.


InputThis Snap has at most one document input view.
OutputThis Snap has at most one document output view.
ErrorThis Snap has at most one document error view and produces zero or more documents in the view.



Excerpt Include
SPD:Snap Label
SPD:Snap Label

Scripting LanguageRequired. Language in which the script is provided. Options available include Python, Javascript, and Ruby.
Default value: Javascript
Script FileRequired. A script file that implements the ScriptHook interface.
Example: slbd://
Default value: [None]


The ScriptHook interface that can be used by the script:

Code Block
package com.snaplogic.scripting.language;

import java.util.Iterator;

 * ScriptHook is the interface that should be implemented as a callback mechanism for
 * ExecuteScript Snap to call into the script.
public interface ScriptHook {

     * Scripts should implement this method to provide application logic.
    void execute();

     * Input is interface that is used by the script to read input from the Snap's input view.
    public static interface Input extends Iterator<Object> {

     * Output is interface that is used by the script to send output data to the Snap output view.
    public static interface Output {

         * Write the data to the Snap output.
         * @param data
        void write(Object data);

     * Error is interface that is used by the script to send error data to Snap error view.
    public static interface Error extends Output {

General Instructions for All Scripting Languages

The script author should declare a global variable named 'hook' (note that this variable name is case sensitive).  
Script engine makes 4 global variables available to the script - input, output, error and log.

  • Variable 'input' is of type ScriptHook.Input defined above.
  • Variable 'output' is of type ScriptHook.Output defined above.
  • Variable 'error' is of type ScriptHook.Error defined above.
  • Variable 'log' is of type org.slf4j.Logger.

Type defined in the schema maps to the Java class as shown below:

 Snap TypeJava class
 NUMBER   java.math.BigDecimal
 INTEGER java.math.BigInteger 
 STRING java.lang.String
 DATETIME org.joda.time. DateTime  
 LOCALDATETIME org.joda.time. LocalDateTime 
 BOOLEAN java.lang.Boolean 
 DATE org.joda.time. LocalDate 
 TIME org.joda.time.LocalTime
 BINARY java.lang.Byte 
 TABLE java.util.List 
 ANY java.lang.Object 
 COMPOSITE java.util.Map 

Objects written to the output view should be of Java types. This is required by some downstream Snaps, for example the Joiner Snap. To write out a Python map to the output view in a Python script, convert the map to a Java HashMap as follows:

Code Block
import java.util
python_map = {}


Script Snap uses Jython engine to execute the scripts written in Python.

Code Block
from com.snaplogic.scripting.language import ScriptHook
from com.snaplogic.scripting.language.ScriptHook import *

class TransformScript(ScriptHook):
    def __init__(self, input, output, error, log):
        self.input = input
        self.output = output
        self.error = error
        self.log = log

    def execute(self):"Executing Transform script")
        i = 0
        while self.input.hasNext():
            data =
            if (i % 2 == 0):
                self.error.write(data * 10);
                self.output.write(data * 10)
            i = i + 1"Finished executing the Transform script")

hook = TransformScript(input, output, error, log)


Script Snap uses JRuby engine to execute the scripts written in Ruby.

Code Block
class MyScript
    include com.snaplogic.scripting.language.ScriptHook
    attr_reader :log, :input, :output, :error
    def initialize(log, input, output, error)
        @log = log
        @input = input
        @output = output
        @error = error
        @array = [java.lang.Integer.valueOf(1), java.lang.Integer.valueOf(2)]

    def execute()
        for element in @array

$hook =$log, $input, $output, $error)


Script Snap uses Rhino engine to execute the scripts written in JavaScript.

Code Block
script = {

    execute : function() {
        for (i = 0; i < data.length; i++) {
var data = [1, 2]
var hook = new com.snaplogic.scripting.language.ScriptHook(script)

Excerpt Include
Script Snap Pack
Script Snap Pack