Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Slow ForAll Patch (Dataverse)

(1) ShareShare
ReportReport
Posted on by 20
Hi everyone,
 
I've inherited a PowerApp which is responsible for raising tickets for services in an organisation.
 
Tickets are raised in 2 stages.  During the initial stage, the customer provides basic details and selects a 'Ticket Type'.  These responses are patched to a Tickets Dataverse table.  During the second stage, the required questions for the selected 'Ticket Type' are pulled from a TicketData table and the results are populated in a gallery to allow the customer to complete the questions specific to the ticket they've selected.
 
The Gallery items property is shown below:
 
galTicketRequiredDetailsTDS Items
Sort(
    Filter(
       TicketData,
        'Ticket ID'.'Ticket Number' = gvCurrentTicket.'Ticket Number' && 'Visible To Customer' <> 'Question Visibility'.'Not Visible'
    ),
    'Question Order Number',
    SortOrder.Ascending
)
 
This functionality is working without issue and when the customer is ready to submit their answers from the gallery, they click a 'Submit' button.
 
The OnSelect property of this button is below:
 
Submit Button OnSelect
ForAll(
    RenameColumns(
        galTicketRequiredDetailsTDS.AllItems,
        lblDataTypeTDS,
        DataTypeTable,
        txtUserResponseTDS,
        AnswerText,
        drpChoiceQuestionTDS,
        AnswerDropDownTable, 
        lblQuestionTDS,
        QuestionTable,
        dteDateQuestionTDS,
        AnswerDatePickerTable,
        chkCheckQuestionTDS,
        AnswerCheckBoxTable,
        cmbMultiChoiceQuestionTDS,
        AnswerMultiChoiceTable,
        lblGUID,
        GUID
    ),
    Switch(DataTypeTable.Text,
        "Multi Line Text",
        Patch(
            [@TicketData],
            ThisRecord,
            {'Customer Response': AnswerText.Text}
        ),
        "Single Line Text",
        Patch(
            [@TicketData],
            ThisRecord,
            {'Customer Response': AnswerText.Text}
        ),
        "Choice",
        Patch(
            [@TicketData],
            ThisRecord,
            {'Customer Response': AnswerDropDownTable.SelectedText.Value}
        ),
       "Date/Time",
        Patch(
            [@TicketData],
            ThisRecord,
            {'Customer Date/Time Responses': AnswerDatePickerTable.SelectedDate}
        ),
        "Attachment",
        Patch(
            [@TicketData],
            ThisRecord,
            {'Customer Response': If(AnswerCheckBoxTable.Value = true, "Yes", "No")}
        ),
        "Multichoice",
        Patch(
            [@TicketData],
            ThisRecord,
            {'Customer Response': Concat(AnswerMultiChoiceTable.SelectedItems.Result, ThisRecord.Result, ",")}
        )
    )
);
 
The problem I am having is poor performance where a user is completing 5 or more questions and Patching to the gallery (at the point they click the 'Submit' button).  Some tickets have over 10 questions and the above 'Submit' code is taking over 30 seconds to be patched to the data source.  In the worst case scenario (one ticket has over 50 questions) it is taking close to 2 minutes to Patch the customers responses to Dataverse!
 
I understand this is because I am doing a ForAll(Patch) and not a Patch(ForAll) or Collection to upsert the responses.  I've read the guidance here and here (thanks to both Craig & Matthew Devaney, I've used your resources extensively while getting to grips with Power Apps!) and I'm aware there are more efficient ways to do this, however, I am struggling to get these methods to work with the above code.
 
Has anyone got an ideas on how best to achieve this in the most efficient way?
  • Verified answer
    XenDance Profile Picture
    20 on at
    Slow ForAll Patch (Dataverse)
    Hi Nandit,
     
    Unfortunately, Forms do not meet my use case in this instance.
     
    I was able to solve this issue by changing the code as per below:
     
    //Create collection to match schema of destination table
    ClearCollect(colSchemaMatchResponse, Sort(Filter([@TicketData], 'Ticket ID'.'Ticket Number' = gvCurrentTicket.'Ticket Number' && 'Visible To Customer' <> 'Question Visibility'.'Not Visible'), 'Question Order Number',SortOrder.Ascending);
     
    //Rename columns
    ForAll(
        RenameColumns(
            galTicketRequiredDetailsTDS.AllItems,
            lblDataTypeTDS,
            DataTypeTable,
            txtUserResponseTDS,
            AnswerText,
            drpChoiceQuestionTDS,
            AnswerDropDownTable,
            lblQuestionTDS,
            QuestionTable,
            dteDateQuestionTDS,
            AnswerDatePickerTable,
            chkCheckQuestionTDS,
            AnswerCheckBoxTable,
            cmbMultiChoiceQuestionTDS,
            AnswerMultiChoiceTable,
            lblGUID,
            GUID
        ),
        Switch(DataTypeTable.Text,
            "Multi Line Text",
            Patch(
                colSchemaMatchResponse,
                ThisRecord,
                {'Customer Response': AnswerText.Text}
            ),
            "Single Line Text",
            Patch(
                colSchemaMatchResponse,
                ThisRecord,
                {'Customer Response': AnswerText.Text}
            ),
            "Choice",
            Patch(
                colSchemaMatchResponse,
                ThisRecord,
                {'Customer Response': AnswerDropDownTable.SelectedText.Value}
            ),
           "Date/Time",
            Patch(
                colSchemaMatchResponse,
                ThisRecord,
                {'Customer Date/Time Responses': AnswerDatePickerTable.SelectedDate}
            ),
            "Attachment",
            Patch(
                colSchemaMatchResponse,
                ThisRecord,
                {'Customer Response': If(AnswerCheckBoxTable.Value = true, "Yes", "No")}
            ),
            "Multichoice",
            Patch(
                colSchemaMatchResponse,
                ThisRecord,
                {'Customer Response': Concat(AnswerMultiChoiceTable.SelectedItems.Result, ThisRecord.Result, ",")}
            )
        )
    );
     
    //Patch collection to data source
    Patch([@TicketData], colSchemaMatchResponse)
     
    Using the above code I was able to speed up the patch from over 2 minutes to under 10 seconds.
     
    If anyone has a more efficient solution I be glad to hear it as 10 seconds is still a bit much for my liking!
  • Suggested answer
    Nandit Profile Picture
    1,563 Super User 2025 Season 1 on at
    Slow ForAll Patch (Dataverse)
    Hi  XenDance,
     
    Have you thought about using Forms to get user responses? That way you just need to use the SubmitForm(FormName) code to run save the information all at once. Is this something that's not going to work for your use case?
     
    Kind regards, 
    Nandit
     

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 1