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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Re-initialize IDs for ...
Power Apps
Answered

Re-initialize IDs for items from a SharePoint List

(0) ShareShare
ReportReport
Posted on by 16

Hi everyone - I am creating a collection from a SharePoint list which has an ID field that is auto-incremented with deleted rows accounted for. Meaning, the list right now is ordered like this:

 

1.

2.

3.

4.

13.

20.

 

In addition to creating the collection, I'm adding a few extra columns. The code looks like this:

 

//Grab and setup table of contents based on selections
ClearCollect(colDocumentTableOfContents,
 AddColumns(
 GenAIDocumentComponents,
 GenAITitle,
 "N/A",
 GenAIType,
 "N/A",
 GenAIBlockText,
 "N/A",
 Zone,
 "unassigned",
 checkValue,
 "unchecked",
 checkFont,
 "#000000",
 ThisType,
 BlockType.Value,
 TypeColor,
 Switch(BlockType.Value,"Image","#0307fc","Legal","#03fc20","Description","#f803fc","Technical","#fca103","#000000"),
 NewID,
 CountRows(colDocumentTableOfContents)
 )
);

 

This creates my collection, importing the ID field with the numbers listed above. I also created a NewID field to attempt to fix my issue, but the value is 0 for each row.

 

The problem is that non-sequential IDs creates all sorts of issues for me. I need the numbers to be sequential, like this:

1.

2.

3.

4.

5.

6.

 

So, I added code underneath the above snippet to reorder the IDs:

//Re-initialize all IDs to ensure they are sequential
ForAll(
 Sequence(CountRows(colDocumentTableOfContents)), Patch(Last(FirstN(colDocumentTableOfContents, Value)),{ID:Value});

)

 

The IDs remain the same:

1.

2.

3.

4.

13.

20.

 

I also tried this:

//Re-initialize all IDs to ensure they are sequential
ForAll(
 Sequence(CountRows(colDocumentTableOfContents)), Patch(Last(FirstN(colDocumentTableOfContents, Value)),{NewID:Value});
)

 

But all NewID values remain at 0; patching is not working.

 

I've been trying to do this for 2 weeks with no end in sight. Can someone tell me what I'm doing wrong?

 

Thanks

Categories:
  • Verified answer
    Gochix Profile Picture
    1,937 Moderator on at

    @Ephezius ,

     

    You can try something like:

    Clear(colDocumentTableOfContents);
    ForAll (GenAIDocumentComponents, 
     Collect(colDocumentTableOfContents, 
     Last(FirstN(AddColumns(GenAIDocumentComponents, 'NewID', CountRows(colDocumentTableOfContents)+1),
     CountRows(colDocumentTableOfContents)+1
     ) 
     )
     )
    )


    _____________________________________________________________________________________
    Please give a thumbs up if I resolved your issue! Please click Accept as Solution to close the topic!

  • Ephezius Profile Picture
    16 on at

    That worked! 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 402 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 296 Most Valuable Professional

Last 30 days Overall leaderboard