# Why is date in string automatically transformed to different date/time format?

**URL:** https://community.integray.com/t/why-is-date-in-string-automatically-transformed-to-different-date-time-format/164
**Category:** Platform discussions
**Tags:** js-mapper
**Created:** [September 26, 2023, 9:01am UTC](https://community.integray.com/t/why-is-date-in-string-automatically-transformed-to-different-date-time-format/164 "2023-09-26T09:01:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Michal](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Michal](https://community.integray.com/u/Michal)
#### Post date: [September 26, 2023, 9:01am UTC](https://community.integray.com/t/why-is-date-in-string-automatically-transformed-to-different-date-time-format/164/1 "2023-09-26T09:01:24Z")

</div>

Hi,

I have a simple task step which parses JSON using JS mapper. As a task step input I send JSON which has been received from API call. The JSON contains property **updated** which is loaded within the step and returned without any further transformation. To my surprise, step returns date/time within different format than it is. Is there any further transformation within JS mapper connecter when the json is returned? Thank you

 ![Screenshot 2023-09-26 at 10.53.19](https://europe1.discourse-cdn.com/flex017/uploads/integray/original/1X/3794032b528257fd10a0ef248d9ceaeb2f03f36e.png)

---

<div class="post-metadata">

### Author: ![tomas](https://avatars.discourse-cdn.com/v4/letter/t/439d5e/32.png) [@tomas](https://community.integray.com/u/tomas)
#### Post date: [September 27, 2023, 7:33am UTC](https://community.integray.com/t/why-is-date-in-string-automatically-transformed-to-different-date-time-format/164/2 "2023-09-27T07:33:57Z")

</div>

Michal,

can you please paste the whole script and input data as code into the topic?

Tomas.

---

<div class="post-metadata">

### Author: ![Michal](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Michal](https://community.integray.com/u/Michal)
#### Post date: [September 27, 2023, 7:42am UTC](https://community.integray.com/t/why-is-date-in-string-automatically-transformed-to-different-date-time-format/164/3 "2023-09-27T07:42:54Z")

</div>

Sure thing! Here is the debug script:

```auto
// creating input data
const _inputString = `[
  {
    "JSON": [
  {
    "defaultLanguage": "cs",
    "devices": [
      {
        "controller": "test-pool-1",
        "companyId": 10,
        "address": {
          "address": "nersfiu, 616 00 Brno, Česko",
          "code": "cz",
          "approximateLng": "16.56829990640513",
          "lng": "16.5672",
          "city": null,
          "postalCode": "616 00",
          "placeId": "EixTb2Nob3JvdmEsIDYxNiAwMCBCcm5vLcW9YWJvdsWZZXNreSwgQ3plY2hpYSIuKiwKFAoSCTXQMQyglhJHEePpPaVjVjQcEhQKEglnlDfEHpQSRxHgzhRmD68ABQ",
          "approximateLat": "49.216644597728575",
          "id": 32,
          "deviceId": 5,
          "lat": "49.2134"
        },
        "customName": "Klaus Flicke",
        "id": 5,
        "updated": "2022-08-29T13:58:45.336Z"
      }
    ],
    "contactEmailAddresses": null,
    "name": "MNB",
    "emailsForEventNotifications": null,
    "id": 10,
    "updated": "2020-09-09T09:18:04.06Z",
    "users": [
      {
        "firstName": "",
        "lastName": "",
        "phoneNumber": null,
        "id": 60,
        "updated": "2020-09-10T11:19:40.362Z",
        "email": "petr.skraivan@mnb.cz"
      },
      {
        "firstName": "",
        "lastName": "",
        "phoneNumber": null,
        "id": 62,
        "updated": "2020-09-10T11:20:02.51Z",
        "email": "martin.risapa@mnb.cz"
      },
      {
        "firstName": "",
        "lastName": "",
        "phoneNumber": null,
        "id": 63,
        "updated": "2020-09-11T07:06:15.031Z",
        "email": "antonin.snajcdr@mnb.cz"
      },
      {
        "firstName": "",
        "lastName": "",
        "phoneNumber": null,
        "id": 674,
        "updated": "2020-09-21T11:16:00.537Z",
        "email": "Jan.Kopvcil@mnb.cz"
      },
      {
        "firstName": "",
        "lastName": "",
        "phoneNumber": null,
        "id": 712,
        "updated": "2020-09-23T06:10:42.96Z",
        "email": "bohdan.blafha@mnb.cz"
      },
      {
        "firstName": "",
        "lastName": "",
        "phoneNumber": null,
        "id": 770,
        "updated": "2020-09-24T14:48:00.24Z",
        "email": "Pavel.Spsulak@mnb.cz"
      },
      {
        "firstName": "Ondrej",
        "lastName": "Sebefdssta",
        "phoneNumber": null,
        "id": 11,
        "updated": "2020-04-24T08:07:34.475Z",
        "email": "ondrej.sebvcesta@sdf.com"
      }
    ]
  }
]
  }
]`
const inputData = JSON.parse(_inputString);

// creating log methods
const log = {
  trace: (str) => console.trace(str),
  debug: (str) => console.debug(str),
  info: (str) => console.info(str),
  warn: (str) => console.warn(str),
  error: function (err) {
    throw err;
  }
}

// creating variables
var outputData;
var _outputString;
const TaskRunID = 1;
const EndpointTokenName = null;
const EndpointTokenID = null;
const DataCheckpoint = null;

// execute method with defined statement
function execute() {
  var output = [];
  var integrationWith = "Enendio-";

  inputData.forEach(row => {
    rowData = row.JSON;

    rowData.forEach(company => {
      //log.info(company.id);
      //--------------------------------
      // parse company data
      //--------------------------------
      var companyID = integrationWith + company.id;
      var companyTimestamp = company.updated;
      var EmailAddress = "";

      if (company.contactEmailAddresses != null) {
        company.contactEmailAddresses.forEach(email => {
          EmailAddress = email.EmailAddress;
        });
      }

      output.push({
        "SectionID": 1043,
        "RequestorLogin": null,
        "NextUserLogin": null,
        "Data":
          company.id + "|" +
          company.name + "|" +
          company.defaultLanguage + "|" +
          EmailAddress + "|" +
          EmailAddress + "|" +
          companyTimestamp + "|" +
          companyID,
        "IntegrationID": companyID,
        "LastUpdate": companyTimestamp
      });

      //--------------------------------
      // parse device data
      //--------------------------------
      company.devices.forEach(device => {
        var deviceID = integrationWith + device.id;
        var address = device.address;
        var deviceTimestamp = device.updated;

        output.push({
          "SectionID": 1045,
          "RequestorLogin": null,
          "NextUserLogin": null,
          "Data":
            deviceID + "|" +
            device.controller + "|" +
            "|" + // customer ID does not exist in import data
            company.name + "|" +
            device.customName + "|" + // contact name does not exist in import data
            "|" + // contact phone does not exist in import data
            "|" + // contact mail does not exist in import data
            "|" + // contact note does not exist in import data
            (address.address == null ? "" : address.address) + "|" +
            (address.city == null ? "" : address.city) + "|" +
            (address.postalCode == null ? "" : address.postalCode) + "|" +
            (address.code == null ? "" : address.code) + "|" +
            deviceTimestamp + "|" +
            address.lat + "|" +
            address.lng + "|" +
            address.approximateLat + "|" +
            address.approximateLng + "|" +
            companyID + "|" +
            device.id,
          "IntegrationID": deviceID,
          "LastUpdate": deviceTimestamp
        });
      });

      //--------------------------------
      // parse user data
      //--------------------------------
      company.users.forEach(user => {
        var userID = integrationWith + user.id;
        var userTimestamp = user.updated);

        output.push({
          "SectionID": 1046,
          "RequestorLogin": null,
          "NextUserLogin": null,
          "Data":
            user.id + "|" +
            user.firstName + "|" +
            user.lastName + "|" +
            user.email + "|" +
            (user.phoneNumber == null ? "" : user.phoneNumber) + "|" +
            userTimestamp + "|" +
            userID + "|" +
            companyID,
          "IntegrationID": userID,
          "LastUpdate": userTimestamp
        });
      });
    });
  });

  //log.info(JSON.stringify(output))

  return output;
};

// show returned data in console
console.log(execute());

```

---

<div class="post-metadata">

### Author: ![libor.zoubek](https://avatars.discourse-cdn.com/v4/letter/l/58f4c7/32.png) [@libor.zoubek](https://community.integray.com/u/libor.zoubek)
#### Post date: [October 11, 2023, 7:43am UTC](https://community.integray.com/t/why-is-date-in-string-automatically-transformed-to-different-date-time-format/164/4 "2023-10-11T07:43:23Z")

</div>

Michal, can you screenshot your output schema? IMHO **LastUpdate** column is not type of Date.

Let me try to describe what happens under the hood

- In order to prepare `inputData` your input data is always processed by `JSON.parse` javascript function, which means that it converts strings which match datetime into javascript `DateTime` objects
- Value returned from JS Mapper statement is always some array of Javascript objects (let’s say rows), which is then internally transformed into internal types which must match your output schema.
- For each returned row, we try to map it’s properties into selected output schema. When we hit **LastUpdate** which is unexpectedly `Date` we _just_ convert it to `String` type. Such _default_ conversion unfortunately does not use DateTime ISO format.

Solutions for you

- Make sure returned values for your JS statement match output schema
- In case you for some reason need **LastUpdate** column as `String` you need to manually convert using `.toISOString()`

---

<div class="post-metadata">

### Author: ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.integray.com/u/system)
#### Post date: [October 18, 2023, 5:02pm UTC](https://community.integray.com/t/why-is-date-in-string-automatically-transformed-to-different-date-time-format/164/5 "2023-10-18T17:02:50Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
