Hi King Java,
Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.
The error "InvalidCodeScriptRuntimeFailure" you're encountering likely stems from how you're trying to access the email body within the JavaScript code. The provided code snippet assumes there's a bodyPreview property within the body
object of the workflowContext.trigger.outputs
.
The workflowContext.trigger.outputs.body.bodyPreview
property might not be the correct way to access the email body text depending on the specific environment you're running the code in.
Even if the bodyPreview
property contains the email body, the code snippet attempts to parse it as JSON twice using JSON.parse(JSON.stringify(jsonString))
. This is unnecessary and might be causing errors if the email body isn't valid JSON.
Here's an improved version of the JavaScript code assuming you have a body
property containing the email text directly:
const emailBody = workflowContext.trigger.outputs.body; // Assuming this holds the email body text
const regex = /originalsrc="https:\/\/(www\.)?\w+(\.\w+).*$"/;
const match = emailBody.match(regex);
if (match) {
return match[1]; // Assuming you only want the URL itself (without the originalsrc=")
} else {
return "No Match";
}
If you find this answer helpful, please click "Accept Answer" and kindly upvote it.