I am receiving website contact forms into, and passing details into mapped Hubspot fields.
One of the form fields is a multi-select, where the values are received as an array of values. I’ve run the Run Javascript app, to convert the array of values to a single joined text string as an object.
The “Run Javascript” result / output is successful, but when I try to map it to a single line text field in Hubspot, I get an error:
Invalid input JSON on line 1, column 370: Cannot deserialize value of type `java.lang.String` from Array value (token `JsonToken.START_ARRAY`)
Below is the code I’m using:
// Initialize an empty array to hold the selections
let selections = e];
// Loop through the inputData to collect the options
for (let key in inputData) {
if (inputData.hasOwnProperty(key) && inputDatamkey]) {
selections.push(inputData.key]);
}
}
// Mapping of form values to HubSpot expected values
const mapping = {
'service': 'Service',
'issuing': 'Issuing',
'acquisition': 'Acquisition',
'other': 'Other',
// Add all your mappings here
};
// Map each selection to the HubSpot expected value
const mappedSelections = selections.map(item => mapping.item.trim()] || item.trim());
// Join the mapped selections into a comma-separated string (with space after comma for readability)
const result = mappedSelections.join(', ');
// Return the result wrapped in Zapier’s required format
const outputString = result.toString();
output = {outputString} ;