1
votes

I have a field dateLastPaid into a JSON Payload. The type of this field is a date in this format 2019-05-10T00:00:00.000-0300. The Salesforce API expects a date-only field but I can't convert it.

I tried to use payload.dateLastPaid as :date{format: "yyyy-MM-dd"} but it still add the time.

Can you help me?

2

2 Answers

2
votes

The problem is trying to format a date. You can format a string, or use a format to parse a string, but in DataWeave, or Java, dates and datetimes don't have format. It works after converting the date from the initial string format to a datetime before trying to format it back into the desired format.

I'm assuming the date is in a JSON string attribute, as you didn't show an actual example.

Input:

{
  "dateLastPaid" :  "2019-05-10T00:00:00.000-0300"
}

DataWeave script:

%dw 1.0
%output application/json
---
{
  date: ( payload.dateLastPaid as :date {format: "yyyy-MM-dd'T'HH:mm:ss.SSSZ"})  as :string {format: "yyyy-MM-dd"} 
}

Output:

{
  "date": "2019-05-10"
}
-1
votes

This script will output the string "2019-05-10"

%dw 2.0
output application/json
var array = [0,1,2,3,4,5,6,7,8,9]
---
array map ((item, index) ->
    payload.dateLastPaid[index]
) joinBy ""