0

I want to extend the "Pass data to scripts in an automatically-run Power Automate flow (preview)" tutorial to include the Body parameter of an email.

function main(
  workbook: ExcelScript.Workbook,
  from: string,
  dateReceived: string,
  subject: string
  body: string) {

}

The input of 'body', however, returns the email as HTML. To handle this, I am parsing the string to pull out the body tag only. Is there a more standard way of doing this?

I found on the Office 365 Outlook connectors docs that 'Body' is under 'Return' and not 'Parameters'. Is this what is preventing a return of the body tag string contents?

Thank you for any answers or suggestions!

Zach
  • 1

1 Answers1

2

You might have to tweak the code a little bit since I don't know how your emails will look. But here is how I would figure it out.

enter image description here

enter image description here

Here is what the email looks like for the example.

enter image description here

Here is the code I used to extract the body. Notice how I use "array(1)", because "array(0)" would be "Hi Test," and "array(2)" would be "Thanks,"

enter image description here

function main(workbook: ExcelScript.Workbook, from: string, dateReceived:string, subject: string, body: string) {
  let array = body.match(/[^\r\n]+/g);
  body = array[1];
  let sheet = workbook.getWorksheet("Sheet3").getRange("A1:D1").setValues([[from, dateReceived, subject, body]]);
}
Ethan
  • 808
  • 3
  • 21