cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
chow0724
New Member

Collection regenerating sequence number

Hi Community, 

 

I've the simple collection which will increasing and index, which currently is working fine.

 

I have the function for the delete the row of the collection, which the sequence number need to regenerate it, how to regenerate the sequence of the number?

 

Below are the code i use:

OnVisible:

ClearCollect(AssetCollection,{LineItem:"Notebook",LineSerialNumber:"",LineSignOutRemarks:"",LineReturnRemarks:"",LineIndex:Value(Last(AssetCollection).LineIndex)


Add Row:

Collect(AssetCollection,{LineItem:"Notebook",LineSignOutRemarks:"",LineReturnRemarks:"",LineIndex:Value(Last(AssetCollection).LineIndex)+1});

Remove Row in Gallery:

Remove(AssetCollection,ThisItem)

1 ACCEPTED SOLUTION

Accepted Solutions
v-bofeng-msft
Community Support
Community Support

Hi @chow0724 :

Do you want to regenerate the LineIndex field based on the deleted record?

This function can be achieved through the updateIf function:

Remove Row in Gallery:

 

UpdateIf(AssetCollection,LineIndex>ThisItem.LineIndex,{LineIndex:LineIndex-1});Remove(AssetCollection,ThisItem);

 

15.gif

I think this link will help you a lot:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-update-updateif

Best Regards,

Bof

View solution in original post

2 REPLIES 2
v-bofeng-msft
Community Support
Community Support

Hi @chow0724 :

Do you want to regenerate the LineIndex field based on the deleted record?

This function can be achieved through the updateIf function:

Remove Row in Gallery:

 

UpdateIf(AssetCollection,LineIndex>ThisItem.LineIndex,{LineIndex:LineIndex-1});Remove(AssetCollection,ThisItem);

 

15.gif

I think this link will help you a lot:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-update-updateif

Best Regards,

Bof

View solution in original post

@v-bofeng-msft it worked! thanks for providing the solution, will also explore the update if function

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (26,798)