Skip to main content

Notifications

Power Automate - General Discussion
Answered

Need help to set variable as integer type and want increment it by 1 for each row in my HTML table response

(0) ShareShare
ReportReport
Posted on by 13

Hi, I have created a flow through which I am getting a output in HTML table on my email. I would like to add 1 other column to that HTML table wherein I would to see numbers in series. I have tried using initialize variable and increment variable but not able to get expected result. I am getting (1,1) in Sr No column response but it should be (1,2,3, etc). Attaching the response of my flow.

So I need to help in order to achieve my goal for my flow.

Thanks in advance.

IAK_0-1698501354154.png

 

  • DamoBird365 Profile Picture
    DamoBird365 8,942 on at
    Re: Need help to set variable as integer type and want increment it by 1 for each row in my HTML table response

    Hi @IAK,

     

    Just to let you know, you could do this with a select - potentially 1 select but I will show you with 2.  First you have your get items, then the select with the specified columns, then the final select can use range on the length of the array to addproperty like so:

     

    DamoBird365_0-1699468019343.png

    This uses the following:

    From: range(0,length(body('Select')))

    Map: addProperty(body('Select')?[item()],'Sr No',add(item(),1))
     
    If you wanted to avoid the 2nd select entirely, you could try:

    From: range(0,length(outputs('Get_items')?['body/value']))

    Map: addProperty(outputs('Get_items')?['body/value']?[item()],'Sr No',add(item(),1))
     
    What these both do is use range to create an array of numbers based on the length.  I.e. if 5 items, starting from 0, it would be [0,1,2,3,4].  Array objects can be selected by integers, starting from 0.  item() is each object in the select or 0,1,2,3,4.  This number has two purposes, to select the object, starting 0 and to create a counter, starting 1, which is why I have add(item(),1) as 0 = 1, 1 = 2 etc.
     
    The original solution will work with a variable and apply to each, but the select method is more efficient but maybe less easy to understand.
     
    I have a few videos on efficiency, if you are interested https://www.youtube.com/playlist?list=PLzq6d1ITy6c3O4AghFQgBkG5CUleOrw3q
     
    Cheers
    Damien

    Please take a look and subscribe to my YouTube Channel for more Power Platform ideas and concepts. Thanks
  • Nived_Nambiar Profile Picture
    Nived_Nambiar 16,911 on at
    Re: Need help to set variable as integer type and want increment it by 1 for each row in my HTML table response

    Hi @IAK 

     

    For making the sr no column at first, what you have to do is you can change the column order while creating HTML table itself , see below for a simple example:

     

    I have intialized a simple array like this

     

    Nived_Nambiar_0-1699197230669.png

     

    Array

    [{"A":1,
    "B":12,
    "C":13},
    {"A":10,"B":20,"C":30}
    ]

     

    Now i want B as first column , then A and then C as column order, for that I have used following syntax while creating HTML table within HTML table action.

     

    Nived_Nambiar_1-1699197316224.png

     

    See i have selected columns field as Custom and manually entered the column order as B,A,C with its field values as item()?['B'] , item()?['A'], item()?['C'] respectively.

     

    So output looks like 

    Nived_Nambiar_2-1699197410597.png

     

     

    Hope the above information helps while building the flow !

     

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

  • IAK Profile Picture
    IAK 13 on at
    Re: Need help to set variable as integer type and want increment it by 1 for each row in my HTML table response

    @Nived_Nambiar Thank you so much for you quick reply with solutions, Appreciate your efforts.

  • Verified answer
    Nived_Nambiar Profile Picture
    Nived_Nambiar 16,911 on at
    Re: Need help to set variable as integer type and want increment it by 1 for each row in my HTML table response

    Hi @IAK 

     

    Sorry i have missed the point of adding select action. for that you have to add select action right after get items and then use the output of select action in apply to each instead of value dynamic content, That's all you have to do !

     

    see below flow for reference !

    Nived_Nambiar_0-1698570773907.png

     

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

     

  • IAK Profile Picture
    IAK 13 on at
    Re: Need help to set variable as integer type and want increment it by 1 for each row in my HTML table response

    Hi @Nived_Nambiar , Thanks for the quick solution to my query. Appreciate a lot, I understood your explanation.

    Just one doubt, As I need 4 columns in my final email output (below is the attached image)

    IAK_0-1698567857564.png

    So to have these columns, I need to use select function at any point right?
    Where I can use that?

     

  • Verified answer
    Nived_Nambiar Profile Picture
    Nived_Nambiar 16,911 on at
    Re: Need help to set variable as integer type and want increment it by 1 for each row in my HTML table response

    Hi @IAK 

     

    using select action won't help you as it would be appending same values again and again.

     

    Another approach to do this would be like below

     

    step1: initialize two variables, one array variables which stores final array which needs to be converted to table and SrNo which stores the index which needs to be added on column SrNo.

    Nived_Nambiar_0-1698563986730.png

     

    Step2: Use Get items to get items from sharepoint

    Nived_Nambiar_1-1698564022550.png

     

    Step 3: Use Apply to each to loop through each items of get items action

    Nived_Nambiar_2-1698564065702.png

     

     Steps to be done in loop are described below

     

    Step 3.1: use compose action which helps to add srNo property to the element currently on which iteration is done like below

    Nived_Nambiar_3-1698564158251.png

     

    Expression:  addProperty(items('Apply_to_each'),'Sr No',variables('SrNo'))

     

    3.2: Add the output of compose action to FinalTable array using append to array action

    Nived_Nambiar_4-1698564230370.png

     

    3.3.  As shown above, use increment variable to increase the value of SrNo variable.

     

     

    Outside of loop , use create html table action to convert FinalTable array to html table format like below

    Nived_Nambiar_5-1698564302481.png

     

     

    Hope this helps !

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

  • IAK Profile Picture
    IAK 13 on at
    Re: Need help to set variable as integer type and want increment it by 1 for each row in my HTML table response

    Hi @Nived_Nambiar , Thanks for your reply. Sharing snap shot of my flow.

    IAK_0-1698555845982.pngIAK_1-1698555862603.png

     

  • Nived_Nambiar Profile Picture
    Nived_Nambiar 16,911 on at
    Re: Need help to set variable as integer type and want increment it by 1 for each row in my HTML table response

    Hi @IAK 

     

    Could you share how flow looks like ?

     

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

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

Kickstarter Events…

Register for Microsoft Kickstarter Events…

Tuesday Tip #12 Start your Super User…

Welcome to a brand new series, Tuesday Tips…

Tuesday Tip #13 Writing Effective Answers…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 144,858

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,505

Leaderboard