Skip to main content

Notifications

Power Platform Community / Forums / Building Power Apps / Slow ForAll Patch (Dat...
Building Power Apps
Suggested answer

Slow ForAll Patch (Dataverse)

Posted on by 11
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?
  • Suggested answer
    Nandit Profile Picture
    Nandit 752 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

September 2024 Newsletter…

September 2024 Community Newsletter…

Community Update Sept 16…

Power Platform Community Update…

Welcome to the new Power Platform Community!…

We are excited to announce our new Copilot Cookbook Gallery in the Community…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 141,122

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,414

Leaderboard