Forum Discussion
13 Replies
- doug_fosslerNew Contributor
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?
- tstackFormer Employee
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?
- doug_fosslerNew Contributor
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);
- SupratimContributor III
@doug.fossler
Please provide the example of input format you have and what is the required output format- doug_fosslerNew Contributor
punchInDate is in “yyyy-MM-dd”
punchInTime is in “HH:mm”punchIn should be something like “MM/dd/yyyy HH:mm”, or “yyyy-MM-dd HH:mm”, or “MMddyyyyHHmm”, etc.
- SupratimContributor III
@doug.fossler
Use this-
$punchInDate.toLocaleDateString(‘{“format”:“yyyy-MM-dd HH:mm”}’if punchInDate is coming as date field , if it’s coming as String then 1st do Date.parse($punchInDate), then use formater in mapper snap
- doug_fosslerNew Contributor
My use case will not allow this to be handled in a mapper. Unless you can tell me how to edit multiple docs based on the prior edits of said docs? I am aware of array’s but they would not solve the problem.
- SupratimContributor III
Please share your json data , which are the input of your script.
- doug_fosslerNew Contributor
An easy example (i.e. only three docs).
[ { "groupBy": { "resourceId": "999000641", "EventDate": "07/24/2017" }, "group": [ { "resourceId": "999000641", "punchInDate": "07/24/2017", "EventDate": "07/24/2017", "break": null, "costCenter": "54770", "timeType": "1", "punchInTime": "06:53", "resourceLastName": "brown", "$rowCountPernull": 1, "WorkedHours": "4", "punchOutTime": "10:53", "siteId": "500", "punchOutDate": "07/24/2017", "resourceFirstName": "Test", "yalePayCode": "1", "optPayTypeId": 1 }, { "resourceId": "999000641", "punchInDate": "07/24/2017", "EventDate": "07/24/2017", "break": null, "costCenter": "54620", "timeType": "1", "punchInTime": "10:53", "resourceLastName": "brown", "$rowCountPernull": 2, "WorkedHours": "3.5", "punchOutTime": "14:23", "siteId": "500", "punchOutDate": "07/24/2017", "resourceFirstName": "Test", "yalePayCode": "1", "optPayTypeId": 1 }, { "resourceId": "999000641", "punchInDate": "07/24/2017", "EventDate": "07/24/2017", "break": null, "costCenter": "64990", "timeType": "1", "punchInTime": "14:23", "resourceLastName": "brown", "$rowCountPernull": 3, "WorkedHours": "5.25", "punchOutTime": "19:38", "siteId": "500", "punchOutDate": "07/24/2017", "resourceFirstName": "Test", "yalePayCode": "1", "optPayTypeId": 1 } ] } ]```
- SupratimContributor III
@doug.fossler
Use the pipeline. Ignore json generator part and go ahead the changes. Let me know the result.DateConvertion_2018_06_29.slp (6.6 KB)
- doug_fosslerNew Contributor
I can do what your pipeline does, the issue is when i have a sub-group of multiple docs that require editing of their fields based on prior and former docs. Unfortunately the attempt to work around the problem does not resolve the problem. It seems that it is not possible to combine two strings and create a date-time in a script snap.