
Email Parser can run JavaScript code as an action within your workflow. This means you can apply custom logic to transform, filter, or enrich your parsed fields using the full power of a scripting language. Whether you need to reformat a phone number, parse a JSON API response, classify a customer by country, or derive new values from existing fields, a JavaScript action gives you the flexibility to do it right inside Email Parser, with no external tools required.
Email Parser lets you use JavaScript in three different places, each serving a distinct purpose:
true to allow the email through, or false to discard it. Learn more about JavaScript filters.Your script must define a function called Run() that receives a single argument: an object called fields. This object contains all the fields available at that point in the workflow, including:
fields.Subject, fields.Body, fields.From, fields.To, and more.customer_address, it will be accessible as fields.customer_address.HttpResponse, your script can access it via fields.HttpResponse.The function must return the fields object. Before returning it, you can add as many new properties as you need. Each new property you add will be available as a field to the next actions in the workflow.
For example, the following minimal script adds a new field called postal_code to the workflow:
function Run(fields) { fields.postal_code = "1234"; return fields; }
After this action runs, the value "1234" will be available in any subsequent action that uses the field postal_code.
Email Parser executes scripts using ECMAScript 2023 (the full specification is available at https://tc39.es/ecma262/2023/). This means you can use modern JavaScript features such as arrow functions, destructuring, async/await, optional chaining, and more. However, there are some important limitations to be aware of:
window, document, or XmlHttpRequest are not available, since Email Parser does not run code inside a browser.fs, http, path, or require() are not available.If your use case requires capabilities beyond what is available in this environment (for example, making HTTP requests from within the script, accessing the local file system, or using third-party libraries), you have two alternatives:
The following annotated script demonstrates several common patterns you will encounter when writing JavaScript actions. It shows how to read fields from the fields object, write new fields back, log messages for debugging, and parse a JSON response produced by a previous HTTP Request action:
/* * Email Parser calls the Run() function, passing in the 'fields' object. This object * includes all the fields from the email, as well as any fields generated by previous * actions or parsers. * * To debug and test your code, consider using a JavaScript IDE like Visual Studio Code or * WebStorm. Alternatively, online tools like JSFiddle or codepen.io can be handy. Once you've * finished testing, simply copy your code and paste it here. * * Please note that the JavaScript version supported here is EcmaScript 2023 * (refer to https://tc39.es/ecma262/2023/ for more details). This version of JavaScript * doesn't support browser-specific objects like 'window', 'document', or 'XmlHttpRequest'. */ function Run(fields) { // Show all property names of the 'fields' object console.log("We have the following fields: " + Object.keys(fields)); // Show the subject of the email console.log("Subject: " + fields.Subject); // If the sender contains john@business.com, create a new field called 'is_john' // and set it to "yes" or "no" if(fields.From.includes("john@business.com")) fields.is_john = "yes"; else fields.is_john = "no"; // JavaScript is very useful for parsing JSON responses from APIs. The EmailParser // action Http Request generates a field called HttpResponse that contains the JSON // response from the API. // Just in case HttpResponse is not defined: if(!fields.HttpResponse) { console.log("No JSON response found in the field HttpResponse"); return; } // Find the property "amount" in the JSON response contained in the field // fields.HttpResponse and set it to the field "amount" var response = JSON.parse(fields.HttpResponse); fields.amount = response.amount; // Find the property "currency" in the JSON response contained in the field // fields.HttpResponse and set it to the field "currency" fields.currency = response.currency; // Any property added or modified in the 'fields' object will be available // to the next actions in the workflow. }
This sample illustrates a few key ideas:
console.log() to write debug messages, which will appear in Email Parser’s action log and help you troubleshoot your script.fields object using standard JavaScript property access (dot notation or bracket notation).fields, such as fields.is_john = "yes".JSON.parse() and extract the values you need.The script editor built into Email Parser is intentionally minimal. It is good enough for pasting and making small edits, but it is not designed for writing or debugging scripts from scratch. It has no syntax highlighting, no auto-complete, and no way to run or test the code directly.
For writing and testing your scripts, we recommend using a proper development environment instead:
The recommended workflow is to write and test your script in one of these tools first, and then copy and paste the finished code into Email Parser’s script editor. This saves time and makes it much easier to catch mistakes before they affect your live workflows.
JavaScript actions are intended for users who need custom logic, but that does not mean you need to be a developer to use them. If you are not familiar with JavaScript, an AI assistant such as ChatGPT, Gemini, or Claude can write the script for you. Here is how to do it effectively:
Run() that takes a single object parameter named fields, and that it must return the same fields object.fields.Phone starts with +44, and if so, set a new field fields.is_from_uk to the value yes.”window, document, or XmlHttpRequest, and without any Node.js modules.The AI will generate a working script that you can copy and paste directly into Email Parser. You may want to test it in JsFiddle or VS Code first, as described in the previous section.
To see a JavaScript action in practice, let’s walk through a complete real-world scenario. Imagine you run an online shop called “Impossible Goods Co.” and your website sends you an email notification every time a customer fills out a contact form. The emails you receive look something like this:
Form Submission
Name: Margaret Holloway
Phone: +44 7700 900341
Email: m.holloway@gmail.com
Hi, I recently purchased the Flux Capacitor and I’m a little concerned, because the manual says it requires 1.21 gigawatts but my home outlet only goes up to 240V. Do you sell an adapter? Also, what is your return policy if I accidentally alter the timeline?
Form Submission
Name: Tomás Ferreira
Phone: +351 912 345 678
Email: tomas.ferreira@outlook.pt
Hello! I want to buy Conan’s sword as a gift for my brother’s birthday. Can you confirm whether it comes in a gift box? Also, does it actually work or is it just decorative? Asking for safety reasons.
Form Submission
Name: Priya Nair
Phone: +33 6 12 34 56 78
Email: priya.nair@yahoo.fr
Good morning. I ordered a Harry Potter wand three weeks ago and it still hasn’t arrived. The tracking number you sent doesn’t work. I’ve tried waving it anyway with no results, so I assume it hasn’t been enchanted yet. Please advise.
The goal is to automatically capture the customer’s information from each email, determine which country they are calling from based on their phone number, and add a new row to a Google Sheet, so your support team has a clean, organized list of inquiries to work from.
Here is how the workflow is set up in Email Parser:

The workflow consists of four steps:
Name, Phone, Message, and Email.Phone field and produces a normalized phone number (in E.164 international format) along with three boolean flags that indicate whether the customer is calling from Spain, France, or Portugal.Here is the JavaScript action script used in step 3. It strips all non-digit characters from the phone number, reconstructs it in the standard +[country code][number] format, and then checks the international dialing prefix to set the three country flags:
// Standardizes European phone numbers to E.164 format (+[country code][number]). // Strips all non-digit characters, preserves a leading + if present, reassembles the number, // and detects whether the number belongs to Spain (+34), France (+33), or Portugal (+351). function Run(fields) { var raw = fields.Phone || ''; // Check if the original number had a leading + (international prefix) var hasPlus = /^\s*\+/.test(raw); // Strip everything except digits var digits = raw.replace(/\D/g, ''); console.log("The telephone number digits are: "+ digits); // Reconstruct in standard format if (hasPlus) { fields.telephone_number_normalized = '+' + digits; } else { // No country code detected -- store as-is (digits only) // You can prepend a default country code here if needed, e.g.: // fields.telephone_number = '+34' + digits; fields.telephone_number_normalized = digits; } // Detect country based on international dialing prefix fields.is_from_Spain = (hasPlus && digits.startsWith('34')) ? 'yes' : 'no'; fields.is_from_France = (hasPlus && digits.startsWith('33')) ? 'yes' : 'no'; fields.is_from_Portugal = (hasPlus && digits.startsWith('351')) ? 'yes' : 'no'; return fields; }
After this action runs, the workflow has access to four new fields: telephone_number_normalized, is_from_Spain, is_from_France, and is_from_Portugal. These, combined with the Name, Email, and Message fields captured by the parser, are passed directly into the Google Sheets action to populate the spreadsheet row.
This example shows how a JavaScript action can act as a lightweight transformation step, bridging the gap between raw parsed data and the clean, structured output that your downstream actions need.