See also:
Overview of scripting in Email Parser
A field can also be populated by running a JavaScript function. As demonstrated below, we implement the ExtractTextFrom() method for this purpose. The ‘input_text’ parameter’s value is the content of the field selected from the ‘Capture text from’ dropdown list.
The function returns the value(s) of the field, which can either be a simple string or an array of strings.
function ExtractTextFrom(input_text) { /* This section locates the index of "Message:" in the input text using the indexOf method. If the marker is found, it extracts the text from this point to the end of the string using substring and trims any leading whitespace. If the marker is not found, the function returns "No match found". */ const startMarker = "Message:"; const startIndex = input_text.indexOf(startMarker); if (startIndex !== -1) { return input_text.substring(startIndex + startMarker.length).trim(); } else { return "No match found"; } /* An alternative way to extract the desired text is by using the split method. This method divides a string into an array of substrings based on a specified separator. */ const parts = input_text.split("\n"); const messageIndex = parts.findIndex(part => part.startsWith("Message:")); if (messageIndex !== -1) { return parts.slice(messageIndex + 1).join("\n").trim(); } else { return "No match found"; } }