-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.js
45 lines (39 loc) · 1.28 KB
/
template.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var script = function() {
var getData = function(params) {
var data = {
//any constants
};
//add input values as-is for troubleshooting errors in the pipeline
var keyArray = params.keySet().toArray();
for (var index in keyArray) {
var key = keyArray[index];
data.inputDataFields[key] = params.get(key);
}
// add any logic, validation, etc...
return data;
};
return {
input: input,
output: output,
error: error,
log: log,
execute: function() {
log.info("script started");
while (input.hasNext()) {
var data = {};
try {
var doc = this.input.next();
data = getData(doc);
// add implementation
output.write(doc, data);
} catch (err) {
data.error = true;
data.errorMessage = err ? err.toString() : "empty";
error.write(doc, data);
}
}
log.info("script finished");
}
};
}();
var hook = new com.snaplogic.scripting.language.ScriptHook(script);