I've been working on Flow and getting jobs from orchestly lately. I had big trouble (and time) for the conversion, but found out the way to go ! This is not so obvious.
1. fetch a job from Orchestly, and get the JSON as returned data.
2. create a deluge script which will handle the list of fields (list jobsfields)
3. I only take care of DATA and DATE_TIME fiel format here.
- for each job_field in job_fields
- if((job_field.get("field_type_value").lower() == "date" || job_field.get("field_type_value").lower() == "date_time") && job_field.get("value") != "")
- // "value": 1614553200000
- // "data_type_value": "BIGINT"
- lineResult = job_field.get("value").toLong().toTime().toString("dd-MM-yyy");
- // lineResult is "01-03-2021" (1st March 2021)
- lineResult = job_field.get("value");
FOR EACH parses each the fields in the list
IF checks for the DATE and DATE_TIME fields only
We convert the data. In the JSON the value is a number : "value": 1614553200000 (EPOCH time if you are wondering)
Line 7: This is were I missed completely the point for hours. I presupposed 1614553200000 (in the JSON) was a BIGINT.
I tried without success
- lineResult = job_field.get("value").toString("dd-MM-yyy");
It is not a BIGINT! It first needs to be converted to Long, then to Time...
You get then lineResult = "01-03-2021" as expected for 1st March 2021.
Little note : I used yyy and not yyyy. In the documentation, toString() uses yyy (3 y) to display full year (4 digits), which is different for toTime() / toDate() who use yyyy (4 y) for year mapping !
Hope this helps