cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Patch a collection of items to SharePoint List

Building an application where users can define steps for a process which are later allocated to other users. Getting a bit stuck here and would appreciate any help 🙂

 

When a user deletes a step in a process, we will need to change the order of all steps after it so that the remainder of the process still makes sense. I have a "Delete Step" button, which first collects all the steps in this process which proceed the current one:

ClearCollect(stepsToModify, Filter('IT New Asset Setup - Build Definition Steps', Step_x0020_Number > stepNumber));

The above is working correctly in retrieving the steps I need, but I cannot for the life of me figure out how to then update the records back into SharePoint.

 

This is what I've tried, which doesn't seem to be working. Any help/ideas appreciated. Cheers Smiley Very Happy

ForAll(stepsToModify,
	Patch('IT New Asset Setup - Build Definition Steps',
		First(Filter('IT New Asset Setup - Build Definition Steps', ID = modSteps.ID)),
		{
			Step_x0020_Number: stepNumber - 1
		}
	)		
)

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
mr-dang
Level 10

Re: Patch a collection of items to SharePoint List


@Anonymous wrote:

 

ClearCollect(stepsToModify, Filter('IT New Asset Setup - Build Definition Steps', Step_x0020_Number > stepNumber));

 

ForAll(stepsToModify,
	Patch('IT New Asset Setup - Build Definition Steps',
		First(Filter('IT New Asset Setup - Build Definition Steps', ID = modSteps.ID)),
		{
			Step_x0020_Number: stepNumber - 1
		}
	)		
)

  


If I understand correctly, you have a Button that deletes a step, and you also want it to autmatically renumber the steps that had followed it.

 

Below are some things that you can look into:

  • Red: this is likely the cause of things not working. First, I assume that your ID column contains unique values. The purpose of this filter is to pull up the unique record that is a part of your datasource. You might need to use RenameColumns() to make PowerApps understand exatly what you want since your datasource and stepsToModify have columns that have the same name. Try this change:

    ForAll(RenameColumns(stepsToModify,"ID","modID"),
    	Patch('IT New Asset Setup - Build Definition Steps',
    		First(Filter('IT New Asset Setup - Build Definition Steps', ID = modID)),
    		{
    			Step_x0020_Number: stepNumber - 1
    		}
    	)		
    )

    This change means that each record in stepsToModify that match the ID in your original datasource will be patched.
  • Blue: the next possible culprit is that the stepNumber is a constant--I assume it is a context variable that you had set upon deleting a record. Is it something like this?:

    UpdateContext({stepNumber: ThisItem.Step_x0020_Number});
    
    Remove('IT New Asset Setup - Build Definition Steps',ThisItem)

    So all steps that you want to rename, might end up with the same step number instead of a step number relative to its original value. E.g. step 16 is deleted, stepNumber variable is set to 16, and steps 17, 18, and 19 are all updated to be 16-1, or 15, instead of 16, 17, and 18 respectively.

    To make the change to the steps relative to their original value, you may need to use RenameColumns() again so that you can distinguish between the original Step_x0020_Number and the column of the same name in stepsToModify:

    ForAll(RenameColumns(RenameColumns(stepsToModify,"ID","modID"),"Step_x0020_Number","step"),
    	Patch('IT New Asset Setup - Build Definition Steps',
    		First(Filter('IT New Asset Setup - Build Definition Steps', ID = modID)),
    		{
    			Step_x0020_Number: step - 1
    		}
    	)		
    )

    This change should make each record in the original datasource change their value in Step_x0020_Number to be one less than before.

Let me know how it goes.

 

@EDIT: I am interested in a solution to this as well. I want to know how to disambiguate more easily--the @[] stuff doesn't make too much sense to me when I'm using ForAll.

Microsoft Employee
@8bitclassroom

View solution in original post

4 REPLIES 4
Community Support Team
Community Support Team

Re: Patch a collection of items to SharePoint List

Hi @Anonymous,

 

Could you please explain a bit for your data source, how the records, and the steps are managed here?

The delete step Action delete a value in a record, or delete an Item in the SharePoint list?

In addition, could you please explain a bit for the meaning of

"

Step_x0020_Number: stepNumber - 1

"

Which you would like this step to achieve?

Regards

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Re: Patch a collection of items to SharePoint List

Hi @v-micsh-msft,

 

The data source is a SharePoint list. In this case a list which details all the Steps for a given Process.

 

The delete action invoked on a Step of a Process will:

  1. Delete the selected item in the SharePoint List.
  2. Find all records in the SharePoint List where the step number is greater than the current step (achieved this with the ClearCollect command), then.
    1. For each record, subtract one from the step number. (so that snippet you've posted should really be:)
      Step_x0020_Number: Step_x0020_Number - 1

 

mr-dang
Level 10

Re: Patch a collection of items to SharePoint List


@Anonymous wrote:

 

ClearCollect(stepsToModify, Filter('IT New Asset Setup - Build Definition Steps', Step_x0020_Number > stepNumber));

 

ForAll(stepsToModify,
	Patch('IT New Asset Setup - Build Definition Steps',
		First(Filter('IT New Asset Setup - Build Definition Steps', ID = modSteps.ID)),
		{
			Step_x0020_Number: stepNumber - 1
		}
	)		
)

  


If I understand correctly, you have a Button that deletes a step, and you also want it to autmatically renumber the steps that had followed it.

 

Below are some things that you can look into:

  • Red: this is likely the cause of things not working. First, I assume that your ID column contains unique values. The purpose of this filter is to pull up the unique record that is a part of your datasource. You might need to use RenameColumns() to make PowerApps understand exatly what you want since your datasource and stepsToModify have columns that have the same name. Try this change:

    ForAll(RenameColumns(stepsToModify,"ID","modID"),
    	Patch('IT New Asset Setup - Build Definition Steps',
    		First(Filter('IT New Asset Setup - Build Definition Steps', ID = modID)),
    		{
    			Step_x0020_Number: stepNumber - 1
    		}
    	)		
    )

    This change means that each record in stepsToModify that match the ID in your original datasource will be patched.
  • Blue: the next possible culprit is that the stepNumber is a constant--I assume it is a context variable that you had set upon deleting a record. Is it something like this?:

    UpdateContext({stepNumber: ThisItem.Step_x0020_Number});
    
    Remove('IT New Asset Setup - Build Definition Steps',ThisItem)

    So all steps that you want to rename, might end up with the same step number instead of a step number relative to its original value. E.g. step 16 is deleted, stepNumber variable is set to 16, and steps 17, 18, and 19 are all updated to be 16-1, or 15, instead of 16, 17, and 18 respectively.

    To make the change to the steps relative to their original value, you may need to use RenameColumns() again so that you can distinguish between the original Step_x0020_Number and the column of the same name in stepsToModify:

    ForAll(RenameColumns(RenameColumns(stepsToModify,"ID","modID"),"Step_x0020_Number","step"),
    	Patch('IT New Asset Setup - Build Definition Steps',
    		First(Filter('IT New Asset Setup - Build Definition Steps', ID = modID)),
    		{
    			Step_x0020_Number: step - 1
    		}
    	)		
    )

    This change should make each record in the original datasource change their value in Step_x0020_Number to be one less than before.

Let me know how it goes.

 

@EDIT: I am interested in a solution to this as well. I want to know how to disambiguate more easily--the @[] stuff doesn't make too much sense to me when I'm using ForAll.

Microsoft Employee
@8bitclassroom

View solution in original post

Anonymous
Not applicable

Re: Patch a collection of items to SharePoint List

Hi @mr-dang, I've just updated my delete button with your code and it appears to be working correctly. Was not aware of this "RenameColumns" function, looks to be useful when I need to patch back a bunch of records for any future application.

 

Thanks for your help! 🙂

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 170 members 5,529 guests
Please welcome our newest community members: