snapation6713
2 years agoNew Contributor III
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!
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!