cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Sage22
Helper I
Helper I

Invalid Argument Type (table), Expecting a record instead

Hi, I am trying to save my updates to both the source table and the collection. However I am getting this error. 
My Gallery form has dropdown inputs. and I have only chosen 5 columns out of 10 to edit in the app. 
On the onstart property of the App I have this:
ClearCollect(TableUpdates,{
Name: "A",
PhoneNumber: "A",
Address:"A",
Occupation: "A",
Age: 1
});
Clear(TableUpdates);


and the  Save button in the onselect property


ForAll(
Filter(
Gallery3.AllItems,
toggler.Value
) As editedrows,
Patch(TableUpdates,
Defaults(TableUpdates), {
Name: editedrows.name_txt.Text,
PhoneNumber: editedrows.phonenumber_txt.Text,
Address: editedrows.address.txt.Text,
Occupation: editedrows.Occup_txt.Text,
Age: editedrows.age.value(age_txt.Text)
})
);Patch('Table3', TableUpdates);
Clear(TableUpdates);

 

5 REPLIES 5
Eelman
Super User
Super User

@Sage22 

Try using

 

ForAll(
	Filter(
		Gallery3.AllItems,
		toggler.Value
	) As editedrows,
		Collect(TableUpdates,
			{
				Name: editedrows.name_txt.Text,
				PhoneNumber: editedrows.phonenumber_txt.Text,
				Address: editedrows.address.txt.Text,
				Occupation: editedrows.Occup_txt.Text,
				Age: editedrows.age.value(age_txt.Text)
			}
		)
);

Thanks @Eelman , I was able to fix the problem, but my save button code seems to be adding new rows in the database instead of updating the rows. 

 

@Sage22 

Oh, so you are Updating items ... not adding new ones? Can you please confirm this please.

 

Trying to update records using TableUpdates in the way you have it setup won't work. You don't have some sort of Reference ID for the the updated information to match with the data in Table3.

 

 

Oh ok. I am using excel as my datasource and I have included a column ID. How can I auto generate this whenever there is a new record or a row is deleted? 

 

@Sage22 

Right, Excel is a poor data source for long term solutions but we can work with it. If you replace all your code, including the OnStart code, with this it'll work

 

// Add to Save Button
ForAll(
	Filter(
		Gallery3.AllItems,
		toggler.Value
	) As editedrows,
		Patch(Table3, editedrows
			{
				Name: editedrows.name_txt.Text,
				PhoneNumber: editedrows.phonenumber_txt.Text,
				Address: editedrows.address.txt.Text,
				Occupation: editedrows.Occup_txt.Text,
				Age: editedrows.age.value(age_txt.Text)
			}
		)
);

 

What you are doing here is updating the data directly from the gallery, there's no need for the intermediate table called TableUpdates, it's not really doing anything from what I can tell

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,811)