You are close, wrap the free parts with a function, and call the function with “input” variable.
Then, select Return Type “Object” or “Array”.
Example input/output
Module Export - quick import into your scenario
You can copy and paste this module export into your scenario. This will import the modules (with fields/settings/filters) shown in my screenshots above.
-
Move your mouse over the line of code below. Copy the JSON by clicking the copy button on the right of the code, which looks like this:
-
Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the editor.
-
Click on each imported module and re-save it for validation. There may be some errors prompting you to remap some variables and connections.
JSON module export — paste this directly in your scenario
{"subflows":[{"flow":[{"id":328,"module":"custom-js:inlineexecutev2","version":1,"parameters":{"__IMTCONN__":2457341,"jscode":"function removeAccents(str) {\n return str.normalize('NFD').replace(/[\\u0300-\\u036f]/g, '');\n}\nfunction formatNamePart(namePart) {\n return namePart.replace(/[^a-zA-ZÀ-ÿ\\s-]/g, '').trim().split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(' ');\n}\nfunction formatForUrl(namePart) {\n return removeAccents(namePart).toLowerCase().replace(/\\s+/g, '-');\n}\nfunction main(inputData) {\n let first_name = inputData.first_name;\n let last_name = inputData.last_name;\n let formattedPrenom = formatNamePart(first_name);\n let formattedNom = formatNamePart(last_name);\n let utm_variable = `${formatForUrl(formattedPrenom)}.${formatForUrl(formattedNom)}`;\n // Retourner les variables comme une liste de valeurs\n return [\n formattedPrenom,\n formattedNom,\n utm_variable\n ];\n}\nreturn main(input);","returnValueType":"array"},"mapper":{"input":"{\n \"first_name\": \"{{329.first_name}}\",\n \"last_name\": \"{{329.last_name}}\"\n}"},"metadata":{"designer":{"x":373,"y":-2984},"parameters":[{"name":"__IMTCONN__","type":"account:custom-js2","label":"Connection","required":true},{"name":"jscode","type":"text","label":"JavaScript Code","required":true},{"name":"returnValueType","type":"select","label":"Return Type","required":true,"validate":{"enum":["text","collection","array","binary"]}}]}}]}],"metadata":{"version":1}}
Note: Did you know you can reduce the size of blueprints and module export code like the above, using the Make Blueprint Scrubber?
e
Hope this helps! Let me know if there are any further questions or issues.
— @samliew
P.S.: Did you know, the concepts of about 70% of questions asked on this forum are already covered in the Make Academy. Investing some effort into it will save you lots of time and frustration using Make later!