Snippets

Hailer Parse input data for zapier (email template)

Created by jari.sinkkonen
const data = JSON.parse(inputData.data);
const fields = data.fields;

const fieldMap = { 
    /// change the numbers to the field id
    textField1: '0', 
    textField2: '1', 
    textField3: '2',
    numField1: '3',
    numField2: '4',
    numField3: '5'
}

function activityValues(fieldMap, fields) {
    Object.keys(fieldMap).forEach(key => {
        let found = false;
        Object.values(fields).forEach(field => {
            if (field.id === fieldMap[key]) {
                fieldMap[key] = field.value;
                found = true;
            } else if (field.id === fieldMap[key].id) {
                fieldMap[key] = field.value[fieldMap[key].target];
                found = true;
            }

        });
        if (!found) {
            fieldMap[key] = null;
        }
    });
    return fieldMap;
}

output = activityValues(fieldMap, fields);

return output;

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.