Created
February 15, 2024 04:06
-
-
Save zackeryfretty/fd9d96e40b6cf29998207b458035edb6 to your computer and use it in GitHub Desktop.
For use with "Code" step, using JavaScript, useful for renaming values that come across from triggers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
For use with "Code" step, using JavaScript, | |
useful for renaming values that come across from triggers. | |
inputData is the Object Zapier creates for the passed values. | |
*/ | |
// Translation Table for Looking up | |
const translationTable = { | |
// "Source" : "Translation" | |
"fog-score{1}" : "Rarely", | |
"fog-score{2}" : "Occasionally", | |
"fog-score{3}" : "Sometimes", | |
"fog-score{4}" : "Often", | |
"fog-score{5}" : "Regularly", | |
} | |
// Start Object | |
const translatedData = {}; | |
// Translator Function | |
const zf_translator = (key,value) => { | |
// Get Values | |
let sourceKey = key; | |
let sourceValue = inputData[key]; | |
let translatedValue = translationTable[sourceValue]; | |
// Add to Object | |
translatedData[sourceKey] = translatedValue; | |
}; | |
// Loop & Translate | |
for( let key in inputData ) { | |
zf_translator(key, inputData[key]); | |
} | |
// Map to Output (bc Zapier) | |
output = translatedData; | |
// Return Object | |
return output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment