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?