Forum Discussion

snapation6713's avatar
snapation6713
New Contributor III
2 years ago
Solved

Issue using mapValues and mapKeys functions in Mapper Snap

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!

  • 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) 

3 Replies

  • SpiroTaleski's avatar
    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)