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 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:
I have the same question (0)
  • Verified answer
    Gochix Profile Picture
    1,935 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

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 Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard