Greetings,
How would I go about using a patch function to create and update a gallery selected item. As it is, my patch function only creates a new record and when trying to edit a gallery selected item, it creates a new record.
*Sample Code*
SubmitBtn (OnSelect)
ForAll(CarCollection, Patch(Details, Defaults(Details), {Date:Date, FirstName:FirstName, LastName:LastName, License:License, Vehicle:Vehicle, InsuranceType:InsuranceType, InsuranceAmount:InsuranceAmount, GasMonthly:GasMonthly}));
Solved! Go to Solution.
Hi@JRobinson12,
Do you want to use the gallery selected to update a certain item and create a new record when opening a new form?
I think you could generate an app directly based on the SP list, which brings you 3 screens, BrowseScreen for a gallery to display all the items, DetailScreen for a view form to display the detailed information, EditScreens for an edit form to create/update a record.
Automatically generated according to SPlist, this app has several default features that can achieve your needs.
1/ Edit a certain record when you select a record in the Gallery
Select an item within the Gallery and it will navigate you to a display form, you could click on the edit button to edit in an edit form.
2/ Create a new record when opening a new form
Click the "+" button and it will navigate you to an edit form directly.
The above app generated based on the SP list needs you to create a new app. If you just want to make a few changes to the original app, you can try the following workaround.
Add 2 screens, Screen1 for a Gallery, Screen2 for the edit form.
Set the OnSelect property of the ">" button within the Gallery as below:
Select(Parent);EditForm(EditForm2);Navigate(Screen2, ScreenTransition.None)
Set the Items property of the Edit form as below:
Gallery2.Selected
Add a "+" button in Screen1 and set the OnSelect property as below:
NewForm(EditForm2);Navigate(Screen2, ScreenTransition.None)
Set the OnSelect property of the submit button as below:
SubmitForm(EditForm2);Navigate(Screen1)
Under this situation, you do not need a Patch() function bu a SubmitForm() function.
The SubmitForm() function could directly submit the edit/create result to the SP list.
Hope it could help.
Best Regards,
Qi
Hi @JRobinson12
I understand that you would simply like to update the selected item in a gallery, not all at once, right?
If that's the case, you don't need a ForAll function. You can do this either inside or outside a gallery. Something like this should suffice:
Patch(
Details,
Gallery1.Selected,
{Date:Gallery1.Selected.Date, FirstName:Gallery1.Selected.FirstName, LastName:Gallery1.Selected.LastName, License:Gallery1.Selected.License, Vehicle:Gallery1.Selected.Vehicle, InsuranceType:Gallery1.Selected.InsuranceType, InsuranceAmount:Gallery1.Selected.InsuranceAmount, GasMonthly:Gallery1.Selected.GasMonthly}
)
If the patch-button is inside a gallery, you could replace Gallery1.Selected with ThisItem or simply remove it completely.
Let me know if it works.
Please click Accept as Solution if my post answered your question. Like my answer? Consider giving it a Thumbs Up. Others seeking the same answers will be happy you did.
Hi@JRobinson12,
Could you please tell me how you update your gallery selected item:
Let me make it easy for you, you use the Defaults() parameter within the Patch() function, it will do create a new record rather than update an existing record.
If you have TextInput within your Gallery, you could try the following formula on the OnSelect property of the Button:
Patch(
[@'Deatils'],
LookUp([@'Deatils'], ID = ThisItem.ID),
{
ColumnName: TextInput1.Text
}
)
On the other hand, combine that with your formula, do you want to write the collection to your gallery selected?
Note that if the collection and you 'Details' share the same column names, you should use the format like Collection[@ColumnName]
If so, please try to modify your formula as below
ForAll(
CarCollection,
Patch(
[@'Details'],
LookUp([@'Details'], ID = CarCollection[@'ID']),
{
Date: CarCollection[@Date],
FirstName: CarCollection[@FirstName],
LastName: CarCollection[@LastName],
...
}
)
)
Hope it could help.
Best Regards,
Qi
Thanks. How would I incorporate this function with "Defaults" function to create a new item. I want when a item is selected from the gallery and changes are made, it updates that record instead of creating a new one and when a new form is created, it creates a new record in the data source
My data source is a sharepoint list
Hi@JRobinson12,
Do you want to use the gallery selected to update a certain item and create a new record when opening a new form?
I think you could generate an app directly based on the SP list, which brings you 3 screens, BrowseScreen for a gallery to display all the items, DetailScreen for a view form to display the detailed information, EditScreens for an edit form to create/update a record.
Automatically generated according to SPlist, this app has several default features that can achieve your needs.
1/ Edit a certain record when you select a record in the Gallery
Select an item within the Gallery and it will navigate you to a display form, you could click on the edit button to edit in an edit form.
2/ Create a new record when opening a new form
Click the "+" button and it will navigate you to an edit form directly.
The above app generated based on the SP list needs you to create a new app. If you just want to make a few changes to the original app, you can try the following workaround.
Add 2 screens, Screen1 for a Gallery, Screen2 for the edit form.
Set the OnSelect property of the ">" button within the Gallery as below:
Select(Parent);EditForm(EditForm2);Navigate(Screen2, ScreenTransition.None)
Set the Items property of the Edit form as below:
Gallery2.Selected
Add a "+" button in Screen1 and set the OnSelect property as below:
NewForm(EditForm2);Navigate(Screen2, ScreenTransition.None)
Set the OnSelect property of the submit button as below:
SubmitForm(EditForm2);Navigate(Screen1)
Under this situation, you do not need a Patch() function bu a SubmitForm() function.
The SubmitForm() function could directly submit the edit/create result to the SP list.
Hope it could help.
Best Regards,
Qi
User | Count |
---|---|
228 | |
103 | |
97 | |
57 | |
31 |
User | Count |
---|---|
283 | |
113 | |
107 | |
63 | |
62 |