cancel
Showing results for 
Search instead for 
Did you mean: 

Issue using mapValues and mapKeys functions in Mapper Snap

snapation6713
New Contributor II

I have data from salesforce that contain fields with a suffix of '__c' and the dates are formatted in UTC. I want to format the incoming data using the mapValue and the mapKey functions to remove the suffix and make all fields lower case AND format the dates into US/Eastern timezone.

I cant get the code to do all that I want: I have the following configuration n my mapper with a $ as my target:

$.mapKeys((value, key)=>key.endsWith('__c')
  ? key.replace('__c','').toLowerCase()
  :key.toLowerCase())
    &&  
 $.mapValues((value, key) => key.toLowerCase().search("createddate") >=0 && value !=null
  ?  Date.parse(value).toLocaleDateTimeString({"timeZone":"US/Eastern"})
   :value) 

This logic formats the dates but not the columns If I reverse it the columns are formatted and not the dates. Same thing if I change the && to ||. How can I get both transformations? Please help!

2 ACCEPTED SOLUTIONS

SpiroTaleski
Valued Contributor

@snapation6713 

Try with this expression: 

$.mapKeys((value, key)=>key.endsWith('__c')   ? key.replace('__c','').toLowerCase()   :key.toLowerCase()).mapValues((value, key) => key.toLowerCase().search("createddate") >=0 && value !=null  ?  Date.parse(value).toLocaleDateTimeString({"format":"yyyymmdd"})   :value) 

View solution in original post

Thank you so much!  It worked!

View solution in original post

3 REPLIES 3

SpiroTaleski
Valued Contributor

@snapation6713 

Try with this expression: 

$.mapKeys((value, key)=>key.endsWith('__c')   ? key.replace('__c','').toLowerCase()   :key.toLowerCase()).mapValues((value, key) => key.toLowerCase().search("createddate") >=0 && value !=null  ?  Date.parse(value).toLocaleDateTimeString({"format":"yyyymmdd"})   :value) 

Thank you so much!  It worked!

snapation6713
New Contributor II

Thank you so much!!! It worked!