06-20-2018 10:51 AM
I am attempting to write javascript for a script snap to manipulate dates, times, and date/times. I am having issues getting a date field plus a separate time field parsed as a DateTime and further having issues when I need to add a duration of time to the DateTime. Are there any examples of this somewhere?
Doug
06-29-2018 10:35 AM
9 days, and no simple answer, just seems like either something is broken and snaplogic is not acknowledging it or this is so simple it is not worth the time which begs the question as to why no answer either way?
06-29-2018 10:40 AM
Can you provide some more details on what you’re trying to do and what issues you’re running into?
There’s quite a few methods on Date objects in the expression language. Is there something in particular you are looking for?
06-29-2018 11:07 AM
Is it not descriptive enough to say i’m attempting to add a time to a date in the script in order to get an example? I’ve tried several methods now to no avail. Here is one of my attempts.
try { load(“nashorn:mozilla_compat.js”); } catch(e) { }
importPackage(com.snaplogic.scripting.language);
importPackage(java.util);
importPackage(java.math);
importPackage(org.joda.time);
var impl = {
input : input,
output : output,
error : error,
log : log,
execute : function () {
this.log.info("Executing Transform Script");
var pid;
var pit;
var pi;
while (this.input != null && this.input.hasNext()) {
try {
var doc = this.input.next();
pid = doc["punchInDate"];
pit = doc["punchInTime"];
pi = LocalDateTime(pid + ' ' + pit);
for (var key in doc) {
if (key != "original"){
wrapper.put(key, doc[key]);
}
}
wrapper.put("punchIn", pi);
this.output.write(doc, wrapper);
}
catch(err) {
var wrapper = new java.util.HashMap();
wrapper.put("errorMsg", err);
this.log.error(err);
this.error.write(wrapper);
}
}
}
};
var hook = new com.snaplogic.scripting.language.ScriptHook(impl);
06-29-2018 11:27 AM
@doug.fossler
Please provide the example of input format you have and what is the required output format