cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
jkperth
Level: Powered On

Error using Collection, ForAll and Patch for multiple selected items

Hi All,

 

I have got a little stuck and would appreciate some help please.

 

The app uses a form to submit new records:

 

 

Create Task Form.png

It allows a user to select an employee and multiple tasks and should (when the tick is pressed) create new records for each.  For example, if you select an employees and two tasks, it will create two new records.  

 

The records are saved into a list ('Task Tracking') with the following columns:

 

Date of Task (Date and Time)

Employee (Lookup - references Id of employee from another list)

Supervisor (Lookup - references Id of supervisor from another list)

Task (Lookup - references Id of task from another list)

 

There is also a list ('Task') where the "Task" from 'Task Tracking' List is looked up.

'Task' List has the following columns:

ID:  The ID number of the task

Field1: The name of the task

 

The code I have on the "OnSelect"  is

 

Note:  DataCardValue10 is a dropdown multiselect list of Tasks

           DataCardValue7 is a date selector

           DataCardValue8 is a dropdown list of Supervisors

           DataCardValue9 is a dropdown list of Employees

 

 

ClearCollect(Collection1, DataCardValue10.SelectedItems);
ForAll(DataCardValue10.SelectedItems, Patch('Task Tracking', Defaults('Task Tracking'), {'Date of task': DataCardValue7.SelectedDate, Supervisor: DataCardValue8.Selected, Employee: DataCardValue9.Selected, Task: DataCardValue10.Selected}))

The problem is that it creates the two records, however for the "Task" column (Lookup Column), it inputs the same task instead of the two selected tasks.

 

How can I rectify this error and how do you know the ID number of a new record(s) that you are creating?

 

Many thanks for your assistance.

 

2 REPLIES 2
jkperth
Level: Powered On

Re: Patch error adding multiple new records

I have now worked out that I need to gather the multiple selected items in a temporary Collection and then I think Patch it all together.  Using this:

 

ClearCollect(Collection1, DataCardValue10.SelectedItems);
ForAll(Collection1,Patch('Task Tracking', {'Date of task': DataCardValue7.SelectedDate, Supervisor: DataCardValue8.Selected, Employee: DataCardValue9.Selected, Task: DataCardValue10.Selected})

 

It now correctly stores the multiple DataCardValue10 items in a Collection.

There are no errors showing in the code, however when I click the OnSelect button no records are added into the 'Task Tracking' table.

Hmmm...Smiley Frustrated

 

Furhermore, if I use Collect and ForAll and Patch the records to the table like so:

ClearCollect(Collection1, DataCardValue10.SelectedItems);
ForAll(Collection1, Patch('Task Tracking', Defaults('Task Tracking'), {'Date of task': DataCardValue7.SelectedDate, Supervisor: DataCardValue8.Selected, Employee: DataCardValue9.Selected, Task: DataCardValue10.Selected}))

It will store all of the records in the List, however EVERY record in the List has the same Task in the "Task" field.  Whatever the last task selected by the user is is what is inserted into the collection Task field.  For example, if you had "Wash Car, Polish Car, Detail Car" all selected, it would store "Detail Car" for the Task for all new records created.

Community Support Team
Community Support Team

Re: Patch error adding multiple new records

Hi @jkperth ,

Have you solved your problem?

If you have solved your problem, please go ahead to click "Accept as Solution" to identify this thread has been solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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 (Last 30 Days)
Users online (5,700)