How to output array elements accordingly inside SendingEmail connector, without using for loop?

asked 2021-11-28T04:39:56.827+00:00
Lee Yong Sheng 41 Reputation points

Hi community fellows

I am developing a monthly report sending feature using Azure Logic Apps, though currently the flow is triggered every half an hour for testing purpose.

The contents of the monthly report are about the turbochargers' health score on a single vessel, the email template as follow:

"Dear Customer,

Please find the summary of turbocharger  health status for “Mth Date”.

Total turbochargers Monitored: XX

Total Turbocharger Healthy: XX

Total Turbochargers Moderate: XX

Total Tubocharger At Risk: XX

Non Healthy turbocharger details:

Moderate:

Vessel Name, IMO, TC Name, number of triggers this month

Vessel Name, IMO, TC Name, number of triggers this month

NA if none

 

At Risk:

Vessel Name, IMO, TC Name, number of triggers this month

Vessel Name, IMO, TC Name, number of triggers this month

NA if none

This is an automated generated message, please do not reply to this email."

This snapshot "email1" is the example I am currently having, whereby the "Moderate" and "At risk" segments are not really correct.

The 2 snapshots "logicapp1" & "logicapp2" show153037-email1.jpg153121-logicapp1.jpg153093-logicapp2.jpg153085-code-1128.txt that I am using Switch case to distinguish the status to be "Healthy". "Moderate" or "At risk".

My question is: is it possible to store the vessel information in an array element accordingly?

Then the array will be parsed out inside the emailSending connector.

The reason for not sending emails inside the for loop is because the report is on vessel basis instead of turbocharger basis.

I attached the Logic Apps code "code_1128" for reference also.

Thank you!

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
1,802 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. answered 2021-11-29T05:26:19.827+00:00
    Pramod Valavala 14,541 Reputation points Microsoft Employee

    @Lee Yong Sheng There are a few ways you could do this and also simplify your flow a bit

    1. Use the Inline Code Action
      This allows you to use JavaScript to process the JSON all in a single step and you could output any array that you just use to send emails from. This simplifies the flow very much and allows for simpler processing of the data using JavaScript methods like map/reduce/etc.
    2. Use an Azure Function
      This is another code option that you could use if JavaScript isn't your thing, and you would prefer using another language like C# or Python. This option has the downside of having another component unlike the inline code action which is contained within the Logic App.
    3. Initialize an object that stores the information for each vessel
      This is like the inline code action except that you would do the same steps using Logic App built-in actions and functions for collections and objects. The flow would be something like this
      • Build an array of vessel identifiers; either from a query or you could add the ones seen in the list of documents while checking for duplicates
      • Build an object with the aggregated data
      • Build an object that has vessel identifiers as keys and the corresponding aggregated data as values
      • Loop over the vessels, getting the data and sending an email for each