Showing results for 
Search instead for 
Did you mean: 

How to get meta data from a document set using script snap?

New Contributor II

I want to get the meta data of a document using a script snap.i prepared the below javascript using script snap. Its working fine at validation time but failing at runtime.
please find my script below.

// Ensure compatibility with both JDK 7 and 8 JSR-223 Script Engines
try { load("nashorn:mozilla_compat.js"); } catch(e) { }

// Import the interface required by the Script snap.

// Import the Java utility classes.

 * Create an object that implements the methods defined by the "ScriptHook"
 * interface.  We'll be passing this object to the constructor for the
 * ScriptHook interface.
var impl = {
     * These variables (input, output, error, log) are defined by the
     * ExecuteScript snap when evaluating this script.
    input : input,
    output : output,
    error : error,
    log : log,

     * The "execute()" method is called once when the pipeline is started
     * and allowed to process its inputs or just send data to its outputs.
     * Exceptions are automatically caught and sent to the error view.
    execute : function () {"Executing Transform Script");
      // var i=0;
        if (this.input.hasNext() ) {
                // Read the next document, wrap it in a map and write out the wrapper
                var doc =;
                 var keyArray = doc.keySet().toArray();
                  var wrapperOut ={};
                 for( var index in keyArray) 
                             var new_data = {};
                            var key = keyArray[index];
                            var type=(!isNaN(parseInt(doc.get(key))) ? 'int' : 'binary');
                           //  wrapperOut.put("data_type",type);
                           //  wrapperOut.put("col_name",key);
                          //  wrapperOut.add(new_data);
             //   wrapper.put("original", doc);
      "Transform Script finished");
            catch(err) {
                var wrapper = new java.util.HashMap();
                wrapper.put("errorMsg", err);
           // i++;
      //  output.write(wrapperOut);" data"+wrapperOut.toString());
       // this.output.write(doc, wrapperOut);

 * The Script Snap will look for a ScriptHook object in the "hook"
 * variable.  The snap will then call the hook's "execute" method.
var hook = new com.snaplogic.scripting.language.ScriptHook(impl);

Where is wrong with this script?Its failing at runtime giving below error: Failed to close subscriber

If the document view is:
items color price

car red 1100
mango green 5

Then my desired output is:
column name type

items string
color string
price int


New Contributor II

The error in the script was due to partial iteration of the, input doc.
The input doc is to be fully iterated otherwise this error will come at runtime like the input is not fully consumed. if required we can break the script into two script.