I have been reading through past posts and trying to get my data output to work but still getting an error that it is not defined in code.
I have a workflow that enrolls any contact where the a combined score threshold is known (I have them setup for each of our 8 products). Then the custom code will map the A1, A2, A3, etc to a string that provides a clearer next step for our sales team.
the third step in the workflow would copy that data output string to a custom single line text property I have setup.
Here is the code:
exports.main = async (event) => {
console.log(“Received Event:”, JSON.stringify(event, null, 2));
if (!event || !event.inputFields) {
return { “outputFields”: { “priority”: “” } }; //
Explicit quotes
}
console.log(“Available Input Fields:”, JSON.stringify(event.inputFields, null, 2));
const score = event.inputFields[“qc_combined_score_threshold”];
if (!score) {
return { “outputFields”: { “priority”: “” } }; //
Explicit quotes
}
console.log(“QC Combined Score Threshold:”, score);
//
Declare the mapping before using it
const scoreMapping = {
“A1”: “High Engagement × Ideal Buyer”,
“A2”: “Moderate Engagement × Ideal Buyer”,
“A3”: “Low Engagement × Ideal Buyer”,
“B1”: “High Engagement × Possible Buyer”,
“B2”: “Moderate Engagement × Possible Buyer”,
“B3”: “Low Engagement × Possible Buyer”,
“C1”: “High Engagement × Unlikely Buyer”,
“C2”: “Moderate Engagement × Unlikely Buyer”,
“C3”: “Low Engagement × Unlikely Buyer”
};
//
Ensure that the score exists in mapping, otherwise return an empty output
if (!(score in scoreMapping)) {
return { “outputFields”: { “priority”: “” } }; //
Explicit quotes
}
const label = scoreMapping[score]; //
Always a string
console.log(“Generated QC Lead Priority:”, label);
return {
“outputFields”: {
“priority”: label //
Explicit quotes
}
};
};