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 / Patching Multiple Reco...
Power Apps
Answered

Patching Multiple Records from ComboBox to Dataverse Lookup Column in PowerApps

(2) ShareShare
ReportReport
Posted on by

I have a combo box labelled "Depends on Task" with an Item property set to Filter(Tasks, Project.Name = 'All-Projects.' Selected.Name). This combo box pulls values from the 'Tasks' table in the "Subject' column, specifically filtering tasks related to the Project record I selected, ensuring only relevant tasks are displayed.

The Save button is configured with the OnSelect property as follows:

Patch(
Tasks,
galTasks.Selected,
{
'Depends On Task': DataCardValue16.Selected
}
);

However, I encounter an issue where it only patches a single record from the Task lookup column, even though I expect it to patch multiple records based on my selection. I have set the SelectMultiple property to true, and I've attempted to modify the line in the patch function from 'Depends On Task': 

DataCardValue16.Selected to 'Depends On Task':  to DataCardValue16.SelectedItems, but this change results in errors.

 

My goal is to patch multiple records from the ComboBox to my Dataverse lookup column "Depends On Task." How can I achieve this functionality?

I have the same question (0)
  • 365-Assist Profile Picture
    2,324 Moderator on at

    Looks like you need the ForAll function. Here is a video that may help explain: https://www.youtube.com/watch?v=bmft4JFWJiY

     

    ---------------------------------------------------
    Please Accept as Solution if it solves your question. Or just give it a Thumbs Up if it is helpful as can help others.

    Subscribe: https://www.youtube.com/channel/UCFpvUlpx84FuIPOdInGKMTw

    Regards
    Darren Lutchner - 365 Assist

  • teach20 Profile Picture
    on at

    I've viewed the tutorial, and it appears that she demonstrated the process using SharePoint. I'm having difficulty figuring out how to adapt the steps to a Dataverse table and columns.

  • 365-Assist Profile Picture
    2,324 Moderator on at

    It doesn't matter the data source the code should be very similar.

  • ivan_apps Profile Picture
    2,187 Moderator on at

    Two ways you can do it, either you iterate through the Gallery Selected Items and run a Patch for each of them, or you collect all the updates into a Collection and submit a single Patch to do them all.

     

    the Collection patch method - https://www.matthewdevaney.com/fastest-way-to-patch-all-gallery-items-power-apps/

     

    you would modify the Filter() inside the ForAll() to be your Gallery.SelectedItems.  Take note that as you are creating the object of updates, you need to use ThisRecord as the pointer to the current record in the ForAll iteration. 
    {

    [your_table_id]: ThisRecord.[your_table_id],

    updatedColThisRecord.[control_with_update]

    }

     

    For Dataverse, your Id column is usually a field with your table name. 

    method 2 - simply remove the collect part of the method above, and instead of creating an object of the updates you want per Gallery SelectedItem, put the Patch here. This will run a patch for each item as opposed to submitting a single patch with several updates.

     

    and yes, he’s using sharepoint but Dataverse works the exact same way. Column names are different but the functions to update records are the same.

  • teach20 Profile Picture
    on at

    I followed her instructions and here is what I did so far:

    I created a form, and within the form, I've added the Depends On Task lookup column in a combo box. The Depend on Task column is in my Tasks table and is also related to the Task table as well (See screenshots below):

    teach20_0-1706810619179.png

     

    teach20_1-1706810649118.png

     

    The combo box Items property for the Depends On Task I have is Filter(Tasks, Project.Name = 'All-Projects'.Selected.Name). I've set it like this so that it only filters tasks that are specific to the Project I selected and not all Tasks of all projects are not listed.

    I've created a Save button and in the OnSelect property I have set it:

    ClearCollect(
    colTasksToPatch,
    ForAll(
    DataCardValue16.SelectedItems,
    {
    Subject: ThisRecord.Subject,
    'Depends On Subtask': ThisRecord.'Depends On Task'
    }
    )
    );

    Patch('Tasks', Defaults(Tasks),
    {'Depends On Task': colTasksToPatch});


    There are errors in my Patch statement below:

    teach20_2-1706811740082.png

    Am I missing something? Thanks for the help!

     




  • teach20 Profile Picture
    on at

    Here is my current code, which includes ForAll and ClearCollect. My clearcollect seems to be fine with no errors but just my Patch. Am I missing something?

    ClearCollect(
         colTasksToPatch,
         ForAll(
                DataCardValue16.SelectedItems,
                {
                          Subject: ThisRecord.Subject,
                         'Depends On Subtask': ThisRecord.'Depends On Task'
                }
          )
    );

    Patch(Tasks, Defaults(Tasks),
    {'Depends On Task': colTasksToPatch});

     

     



  • ivan_apps Profile Picture
    2,187 Moderator on at

    What is ‘Depends on Task’, is this a lookup to a single Task?.

     

    from what you posted, your Patch() says: - Create a single new Task with default values, update the ‘Depends on Task’ column to be a collection of objects defined as {subject: xx, ‘depends on sub task’: xxx} - this is incorrect.

    Assuming Depends on Task is a lookup to another Task - you have to define you’re setting this column as a ‘Record’ type. You’re currently defining it as a collection of objects - when it should be defined as a reference to another Table via a Lookup() or other reference.


    are you trying to patch multiple existing Tasks or create multiple new Tasks with the same dependency reference?

  • teach20 Profile Picture
    on at

    That makes sense now. Thank you for this. I'm trying to patch multiple existing Tasks. What would be the next steps?

  • ivan_apps Profile Picture
    2,187 Moderator on at

    Instead of Defaults() it should be a table of existing Tasks. 

    the second parameter in your patch should be a collection of updates for each of those tasks. However you still have to define what type of column ‘Depends on Task’ is, as you have to match the data type in your update. If it’s a lookup - it has to be a ‘Record’ type. If it’s a text or choice, you have to match that data type in your update.

     

    Note: you have to include you table primary key/GUID so the patch knows which row to update.

     

    Patch(Tasks,

    colGalleryUpdates.ID,

    colGalleryUpdates

    );

  • teach20 Profile Picture
    on at

    For the Defaults(), the table of existing tasks is Tasks itself - do I need to create another table?

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