Summary:
PowerApps Canvas: 'Invalid argument type' on Collect from identical Dataverse Filters—only when Trains section matches others; workaround nests tables.
Problem:
In the Participant screen (somewhere in the middle of the wizard-like app) I want to build and maintain a collection of services (colServiceData) for the selected participant in order to dynamically show cards with some basic data and set flagServiceSelected when navigate to the service screen for editing/viewing or want to delete the selected service.
When I start to collect (colServiceData) from services one-after-another, it works fine with the below code. HOWEVER all Collect calls in the If block fail with 'Invalid argument type' errors—but only when 4.f uses the exact ForAll(Collect()) pattern matching 4a–4e/4g–4h.
Strangely enough the error disappears if I delete the snippet in 4.f section or I change it like it is now (to collect the table returned by ForAll), which is utterly different how I collect from the other tables and is not what I intend, it works. I want to have a flattened table with each row a record not a table. AIs suggested the current ForAll-inside-Collect creates nested tables (ForAll returns table, causing potential data loss on flatten)
What especially strange is that only happens when the 4.f section is the same as the others, as it should be, within the If() block. When I delete or change that part, it works. However that means the colServiceData will have no coherent structure/schema.
Context:
I have 8 service tables in dataverse, each has a lookup field to Participation table which in turn has lookup fields to Traveler and Travel tables. The architecture is to connect the services to travelers (*-1) and travelers to travels (*-1).
The dataverse tables are the very same when it comes to GUID and lookup, I double checked them two times. Differences are only in other columns.
AIs keep telling it is likely schema inference failure, but that seems impossible.
(one last note, my original code contains many hungarian parts, as the dataverse table and column names are in hungarian, and I changed those here to english, but that's why there are some in quotes)
Here is the code.
// Clear and prepar necessary collections
ClearCollect(colReszvetelData, Blank());
Clear(colServiceData);
// Request data from Participants and Travelers datasource, merge, and store it to colParticipantData (only if Edit or View)
If(
varParticipantMode <> "New",
ClearCollect(
colParticipantData,
AddColumns(
Filter(
Participants,
// Filter: only Participants belonging to the current Travel
Travel.TravelId = varUtazas.TravelId
),
// Merged Traveler fields — LookUp into Traveler via the lookup on each row
'Traveler Name',
LookUp(Travelers, Traveler = ThisRecord.Traveler, 'Traveler name'),
'Traveler Email',
LookUp(Travelers, Traveler = ThisRecord.Traveler, 'Traveler email address')
)
)
);
//HERE is the probelm with 4f. ONLY. If it is the same as the others, the whole block breaks, if it is changed to Collect first then ForAll there's no error. WTF?
/* Request only those data to be shown from all Services datasource that is linked to the current Participant
and store colServiceData (only if Edit or View). Service records are only collected if their parent Participant belongs to the current Travel.
By chaining the 8 Collects, they all append to the same colServiceData.
*/
If(
varReszvetelMode <> "New",
/* --- 4a. Planes --- */
ForAll(
colParticipantData As CurrentParticipant,
Collect(
colServiceData,
AddColumns(
Filter(
Planes,
Participant.ParticipantId = CurrentParticipant.ParticipantId
),
participantId, CurrentParticipant.ParticipantId,
ServiceType, "Plane",
ServiceRecordId, ThisRecord.PlaneId,
DisplayLabel, ThisRecord.Departure &
" → " &
ThisRecord.Destination &
", " &
Text(ThisRecord.'SegmentType') &
" " &
Text(ThisRecord.'SegmentDirection')
)
)
);
/* --- 4b. Hotel --- */
ForAll(
colParticipantData As CurrentParticipant,
Collect(
colServiceData,
AddColumns(
Filter(
Hotels,
Participant.ParticipantId = CurrentParticipant.ParticipantId
),
participantId, CurrentParticipant.ParticipantId,
ServiceType, "Hotel",
ServiceRecordId, ThisRecord.HotelId,
DisplayLabel, ThisRecord.HotelName &
", " &
Text(ThisRecord.Checkin, "MM.dd") &
" - " &
Text(ThisRecord.Checkout, "MM.dd")
)
)
);
/* --- 4c. CarRent --- */
ForAll(
colParticipantData As CurrentParticipant,
Collect(
colServiceData,
AddColumns(
Filter(
CarRents,
Participant.ParticipantId = CurrentParticipant.ParticipantId
),
participantId, CurrentParticipant.ParticipantId,
ServiceType, "CarRent",
ServiceRecordId, ThisRecord.CarRentId,
DisplayLabel, ThisRecord.PickupPlace &
", " &
Text(ThisRecord.PickupDate', "MM.dd")
)
)
);
/* --- 4d. Registration --- */
ForAll(
colParticipantData As CurrentParticipant,
Collect(
colServiceData,
AddColumns(
Filter(
Registrations,
Participant.ParticipantId = CurrentParticipant.ParticipantId
),
participantId, CurrentParticipant.ParticipantId,
ServiceType, "Registration",
ServiceRecordId, ThisRecord.RegistrationId,
DisplayLabel, ThisRecord.Title &
" " &
ThisRecord.Amount
)
)
);
/* --- 4e. Transfer --- */
ForAll(
colParticipantData As CurrentParticipant,
Collect(
colServiceData,
AddColumns(
Filter(
Transfers,
Participant.ParticipantId = CurrentParticipant.ParticipantId
),
participantId, CurrentParticipant.ParticipantId,
ServiceType', "Transfer",
ServiceRecordId, ThisRecord.TransferId,
DisplayLabel, Text(ThisRecord.'SegmentType') &
" " &
Text(ThisRecord.'SegmenDirection') &
", " &
Text(ThisRecord.'TransferType')
)
)
);
/* --- 4f. Train --- */
Collect(
colServiceData,
ForAll(
colParticipantData As CurrentParticipant,
AddColumns(
Filter(
Trains,
Participant.ParticipantId = CurrentParticipant.ParticipantId
),
participantId, CurrentParticipant.ParticipantId,
ServiceType, "Train",
ServiceRecordId, ThisRecord.TrainId,
DisplayLabel, Text(ThisRecord.DepartDate, "MM.dd")
)
)
);
/* --- 4g. Visa --- */
ForAll(
colParticipantData As CurrentParticipant,
Collect(
colServiceData,
AddColumns(
Filter(
Visas,
Participant.ParticipantId = CurrentParticipant.ParticipantId
),
participantId, CurrentParticipant.ParticipantId,
ServiceType, "Visas",
ServiceRecordId, ThisRecord.VisaId,
DisplayLabel, ThisRecord.Country &
", " &
Text(ThisRecord.DateIn, "MM.dd") &
" - " &
Text(ThisRecord.DateOut, "MM.dd")
)
)
);
/* --- 4h. Insurance --- */
ForAll(
colParticipantData As CurrentParticipant,
Collect(
colServiceData,
AddColumns(
Filter(
Insurances,
Participant.ParticipantId = CurrentParticipant.ParticipantId
),
participantId, CurrentParticipant.ParticipantId,
ServiceType, "Insurance",
ServiceRecordId, ThisRecord.InsuranceId,
DisplayLabel, ThisRecord.Country &
", " &
Text(ThisRecord.'DateOut', "MM.dd") &
" - " &
Text(ThisRecord.'DateIn', "MM.dd")
)
)
)
);