Javascript Code (Zapier -> Make.com)

Hello,

I have a code that works in Zapier, but I’m having trouble getting it to work in Make.com using the “0codekit” module.

My Code:

//Kitchen Countertop Dimensions, Number of Cabinets, Number of Fronts, Number of Shelves
const inputText = inputData['daten'];

const matches = inputText.match(/Length of Kitchen Countertop\s*\d*\s*:\s*(\d+(\.\d+)?)/g);
const result = matches && matches.length > 0 ? {} : "none";

if (matches) {
  matches.forEach((match, index) => {
    const [, value] = match.split(":").map(s => s.trim());
    const numValue = parseFloat(value.replace(",", "."));
    result[`Length of Kitchen Countertop ${index + 1}`] = isNaN(numValue) ? value : `${numValue} m | `;
  });
}

const korpusRegex = /Cabinets :[\n\s]*- (\d+)/i;
const match = inputText.match(korpusRegex);
const result2 = match ? `${match[1]} pcs.` : "none";

const endText = "Foil for Fronts :";
const outputText = inputText.substring(0, inputText.indexOf(endText))
                             .replace(/\d+X Shelf/g, "")
                             .replace(/\[n\]\s*/g, "\n")
                             .replace(/:.*/g, "")
                             .replace(/(?:N|U|K|F)\d+/g, "")
                             .replace(/[^\d\n+X]+/g, " ")
                             .replace(/\s+/g, function(match, offset, string) {
                                if (string[offset - 1] === "X") {
                                  return " ";
                                }
                                return "+";
                             })
                             .replace(/\++/g, "+")
                             .replace(/^\+|\+$/g, "")
                             .replace(/X/g, "*");

const result3 = eval(outputText) ? `${eval(outputText)} pcs.` : "none";

const regalMatches = inputText.matchAll(/((\d+)?X\s*)?Shelf/g);
let totalShelves = 0;

for (const regalMatch of regalMatches) {
    const multiplier = regalMatch[2] ? parseInt(regalMatch[2], 10) : 1;
    totalShelves += isNaN(multiplier) ? 0 : multiplier;
}
............. some more code .......

const plzMatch = inputText2.match(plzRegex);
const cityMatch = inputText2.match(cityRegex);
const addressMatch = inputText2.match(addressRegex);
const infoMatch = inputText2.match(infoRegex);

let outputInfo = {};

if (plzMatch) {
  const plz = plzMatch[1].trim();
  outputInfo["ZIP Code"] = plz;
}

if (cityMatch) {
  const city = cityMatch[1].trim();
  outputInfo["City"] = city;
}

if (addressMatch) {
  const address = addressMatch[1].trim();
  outputInfo["Address"] = address;
}

if (infoMatch) {
  const info = infoMatch[1].trim();
  outputInfo["Info"] = info;
}

return { 
    output1: result, 
    outputCabinets: result2, 
    outputFronts: result3, 
    outputShelf: resultShelf,
    foilFronts: output1,
    foilCabinets: output2,
    foilCountertop: output3,
    imageUrls: outputObj,
    InfoBox: outputInfo
};

Thank you for helping. I want to switch from Zapier to Make.com, but I am encountering issues with some Zaps while trying to integrate it on Make.com. Additionally, I find it frustrating that you can’t simply execute code like in Zapier and instead require an external module, which also comes with additional costs.

Welcome to the Make community!

That’s a great idea!

You can submit this suggestion to the Idea exchange, under Platform ideas. Don’t forget to search for it first, just in case someone already suggested it!

Where are you having trouble with this? Can you share any error messages, if any?

2 Likes

Welcome to the Make community!

1. Scenario blueprint

Please export the scenario blueprint file to allow others to view the mappings and settings. At the bottom of the scenario editor, you can click on the three dots to find the Export Blueprint menu item.

Screenshot_2023-08-24_230826
(Note: Exporting your scenario will not include private information or keys to your connections)

Uploading it here will look like this:

blueprint.json (12.3 KB)

2. And most importantly, Input/ Output bundles

Please provide the output bundles of the modules by running the scenario, then click the white speech bubble on the top-right of each module that runs successfully, save the bundle contents in your text editor as a bundle.json file, and upload it here into this discussion thread.
Screenshot_2023-10-06_141025

Providing the output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.

Following these steps will allow others to assist you here. Thanks!

2 Likes

i got it :slight_smile: i use python so it works now byebye Zapier and welcome Make.com :slight_smile:

3 Likes