cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Adding column at the beginnging of mapped array

SL12345
New Contributor III

Hi snaplogic experts,

i have csv file with 56 columns. In order not to map field after field and have 56 rows in mapper, iam using this function (mapping and replacing . with , ).

$.mapValues(x => x.replaceAll('.', ','))

but my problem is: i need to add yesterdays date as first column.

is there any chance to add column to this function or do i need to map all columns and new column will be added as first column?

thank you

1 ACCEPTED SOLUTION

koryknick
Employee
Employee

Iโ€™m not sure what the mapValues is doing in your example, but you can use extend() to add to the JSON document. In this case, you would create a new object with your โ€œyesterdayโ€ field and extend that with the incoming object. Something like this:

{ "yesterday" : Date.now().minusDays(1).toLocaleDateString() }.extend($)

View solution in original post

1 REPLY 1

koryknick
Employee
Employee

Iโ€™m not sure what the mapValues is doing in your example, but you can use extend() to add to the JSON document. In this case, you would create a new object with your โ€œyesterdayโ€ field and extend that with the incoming object. Something like this:

{ "yesterday" : Date.now().minusDays(1).toLocaleDateString() }.extend($)