web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to place string be...
Power Automate
Unanswered

How to place string before an array?

(0) ShareShare
ReportReport
Posted on by 11

Is there a way to place text - pulled from a list - before an array? 

 

For instance, my current table looks like this:

Question user needs to answer?
Answer to question.
Question user needs to answer?
Answer to question.

 

I am looking to include something that would look like this:

SECTION ONE
Question user needs to answer?
Answer to question.
Question user needs to answer?
Answer to question.
SECTION TWO
Question user needs to answer
Answer to question.


Ideally, this text would only be visible if the array is not empty.  If it is empty, no section header for that array.

My use case is as follows:  I'm creating a document by generating a custom table.  The values are stored in a Dataverse table, and the user adds records through a PowerApps canvas app.   There are eight sections of this form, though the user may not fill out all questions.  In the form, they are routed to different sections based on their answers.  The requirements are that by the end of this form, they will have a document that only includes the sections and corresponding questions that they answered.  

 

Since I am creating the table dynamically, I had to create a reference list in SP that stores all the internal names of the fields from the Dataverse.   I have a 'Apply to all' condition that cycles through all the internal names in SP, checks if they exist in the Dataverse [Get row by id query], and if they do, it grabs the answer and corresponding question from each section and appends this information to an array.  There are eight arrays to correspond with the eight sections.

 

I need to be able to insert a row heading at the beginning of each section Array.  Here are the actions in my flow that create the table:

 

flow_01.jpg

 

The concat formulas are:

concat('<tr><td><p><b>',item()['Question'],'</b></p><p>', item()['Answer'],'</p></td></tr>')

 

In the join I am doing the following:

join(body('section_one_select'),decodeUriComponent('%0A'))
Categories:
I have the same question (0)
  • highlyAnnoyed Profile Picture
    11 on at

    Okay never mind... just set the values to what I needed when I initialized the variable.   

    EDIT:  Never mind again, realized this doesn't really meet the ask.  I need to be able to only show the headers if the array is not empty, and this will always have content in the array.  ugh, back to the drawing board.

  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    Hopefully this will get what you're after.

     

    Below is the full flow. I'll go into each of the actions.

    grantjenkins_0-1671606357836.png

     

    The three array variables contain your questions and answers. Note that arrSectionThree is empty so we don't want a section header for it.

    grantjenkins_1-1671606419047.png

     

    The three Selects are the same as what you had before. The expression used is:

     

    concat('<tr><td><p><b>',item()['Question'],'</b></p><p>', item()['Answer'],'</p></td></tr>')

     

    grantjenkins_2-1671606495495.png

     

    Compose builds up the HTML table. The expressions used are:

     

    if(not(equals(length(variables('arrSectionOne')),0)), concat('<tr><th>Section One</th></tr>', join(body('Select_One'), '')), null)
    
    if(not(equals(length(variables('arrSectionTwo')),0)), concat('<tr><th>Section Two</th></tr>', join(body('Select_Two'), '')), null)
    
    if(not(equals(length(variables('arrSectionThree')),0)), concat('<tr><th>Section Three</th></tr>', join(body('Select_Three'), '')), null)

     

    grantjenkins_3-1671606584397.png

     

    Compose Style has some CSS to style the table.

     

    <style>
     table {
     border-collapse: collapse;
     width: 100%;
     }
     table td,
     table th {
     border: 1px solid #ddd;
     padding: 5px;
     text-align: left;
     }
     table th {
     background-color: #1C6EA4;
     color: white;
     }
    </style>

     

    grantjenkins_4-1671606633255.png

     

    And finally, Send an email contains the output from the Compose Style and Compose.

    grantjenkins_5-1671606674331.png

     

    The email for this example would look like:

    grantjenkins_7-1671606838714.png

     

  • highlyAnnoyed Profile Picture
    11 on at

    Wow, thank you so much for this!  I actually ended up doing a much less elegant [and less efficient] way to do the same thing.  Basically using conditional actions to check if the section content arrays were empty, then if they weren't, setting a variable to the section header content then adding that content in a select and adding the select to the compose.  I edited it to be somewhat similar to yours and used the empty() function instead of the length. Thanks so much!!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard