cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
yupabs
Helper I
Helper I

Create Sequence # within an array

I have multiple set of tasks lists per user and i need to have a sequence # depends on the number of tasks.

 

For ex. below 4 tasks for an assigned user, so i need to stamp S.No. from 1 to 4. Other users may have 1 or 5 or 10, so accordingly I have to set the number of tasks.

 

[
{
"S.No.": "1",
"Task Id": "inZRueq85kixDu3zTH1zOGQAERb5",
"Aging": "0 Day(s)"
},
{
"S.No.": "2",
"Task Id": "V_j6S9Cxl0uoyT40Uy6HkmQAFbXJ",
"Aging": "0 Day(s)"
},
{
"S.No.": "3",
"Task Id": "oYDcuvc-Nkmn1MCwkaA1oGQADcdV",
"Aging": "0 Day(s)"
},
{
"S.No.": "4",
"Task Id": "A6ZGZNSFik699cFsdh9r-mQAGtAM",
"Aging": "0 Day(s)"
}
]

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User
Super User

Something like this should do what you want:

https://ibb.co/cTZ7sDB

2021-08-23_00-47-54.png

Output generated is:

[
  {
    "S.No": 1,
    "Task Id": "inZRueq85kixDu3zTH1zOGQAERb5",
    "Aging": "0 Day(s)"
  },
  {
    "S.No": 2,
    "Task Id": "V_j6S9Cxl0uoyT40Uy6HkmQAFbXJ",
    "Aging": "0 Day(s)"
  },
  {
    "S.No": 3,
    "Task Id": "oYDcuvc-Nkmn1MCwkaA1oGQADcdV",
    "Aging": "0 Day(s)"
  },
  {
    "S.No": 4,
    "Task Id": "A6ZGZNSFik699cFsdh9r-mQAGtAM",
    "Aging": "0 Day(s)"
  }
]

Blog: tachytelic.net

YouTube: https://www.youtube.com/c/PaulieM/videos

If I answered your question, please accept it as a solution 😘

View solution in original post

12 REPLIES 12
eliotcole
Super User
Super User

Do these need to have any particular order? Or do you just need each of them to have an S.No?

 

Also, is this "S.No." something that needs to increase permanently? Or simply just in the confines of each run of the flow?

 

If the former, then you should really setup a SharePoint list, and just put/take the data from there.

 

If it's the latter, I'd recommend running a simple 'Apply to each' on the array to create a new array, and have an sNoVAR integer variable increment by 1 each time, add that to a compose to make the JSON object, then append that to the new array.

 

I'll post pics in a second of that example, but it'll do the job for you. In terms of directly inserting it without a loop, my brain isn't switched on right now, so I might not be able to.

 

One pic!

 

iterating a number.jpg

 

yupabs
Helper I
Helper I

Thanks for your response @eliotcole . 

 

But i need to add the logic while filtering the data from JSON object. Output will be like below.

 

S.No.IncidentTask IdAgingLink
1INCXXXXXTaskXXXX1 Day(s)https://xxxxxx.com
2INCXXXXXTaskXXXX1 Day(s)https://xxxxxx.com
3INCXXXXXTaskXXXX1 Day(s)https://xxxxxx.com
4INCXXXXXTaskXXXX1 Day(s)https://xxxxxx.com

 

I have a select step below which i need to add a logic for S.No. (Serial No.).

 

yupabs_0-1629596754476.png

 

eliotcole
Super User
Super User

Cheers, @yupabs, what does the input(s) look like, though?

 

(would be great to see your whole flow, if you can, please)

yupabs
Helper I
Helper I

Hi @eliotcole ,

Below is the flow.

 

1. List the tasks

2. filter array (where completed date is null)

3. select userid column

4. set variable to get distinct value

5. Loop thru each users from step 4.

 

yupabs_1-1629607243172.png

 

Now here in the loop, what i want is to get all tasks assign to each user and create HTML table with some details like title, created date, task id link and sequence#.

 

yupabs_2-1629607539472.png

 

 

eliotcole
Super User
Super User

... and what does the input data look like?

 

Can you give us data that you have in the excel table? If you need to be sensitive, make it up, but it must represent all the columns that are sent through.

 

Paulie78
Super User
Super User

Something like this should do what you want:

https://ibb.co/cTZ7sDB

2021-08-23_00-47-54.png

Output generated is:

[
  {
    "S.No": 1,
    "Task Id": "inZRueq85kixDu3zTH1zOGQAERb5",
    "Aging": "0 Day(s)"
  },
  {
    "S.No": 2,
    "Task Id": "V_j6S9Cxl0uoyT40Uy6HkmQAFbXJ",
    "Aging": "0 Day(s)"
  },
  {
    "S.No": 3,
    "Task Id": "oYDcuvc-Nkmn1MCwkaA1oGQADcdV",
    "Aging": "0 Day(s)"
  },
  {
    "S.No": 4,
    "Task Id": "A6ZGZNSFik699cFsdh9r-mQAGtAM",
    "Aging": "0 Day(s)"
  }
]

Blog: tachytelic.net

YouTube: https://www.youtube.com/c/PaulieM/videos

If I answered your question, please accept it as a solution 😘

yupabs
Helper I
Helper I

@Paulie78 - this is what i was looking for! Thanks so much for your help. 👍

eliotcole
Super User
Super User

@Paulie78 how doe... that seems great ... I can't seem to understand how the add is adding to nothing. How does that work?

 

Plus I can't seem to get it work ... did you get that functioning, @yupabs? Also, is your incoming data like in Paulie's Tasks image?

Paulie78
Super User
Super User

Hi @eliotcole 

 

It is not adding to nothing, it is adding to a number (which starts at zero). I will explain a bit more...

 

The select action requires an array input. The "Range" function will produce an array of numbers. In the case of this flow the numbers will range from zero, up to the count of the array. So in this example something like:

 

[0,1,2,3]

 

Is what is passed into the "Select" action. So the reference to item() within the select will be one of those numbers. Because arrays are numbered from zero, but the original poster wants his sequence to start from 1, the add is adding 1 to item() which starts at zero, ends at 3.

 

The item() is also used to refer to the index of the original array, selecting the relevant record. Does that make sense?

 

eliotcole
Super User
Super User

Ahhhhhhhh. That's great, cheers, mate. I'd missed the range part in the input. 👍

I love your answer @eliotcole. It helps me a lot. Thank you so much

eliotcole
Super User
Super User

@AbdulWahab  ... Thank you! But you really should use Paulie's, it's amazing!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (4,270)