I have a 2 Sharepoint lists which are linked by a number field called "tripid"
The first list is Trips and contains details of people's field trips, the second list is called TripDetails and it contains a record for every day the person is out on the trip - this could be just 1 day or up to 10 days - both lists have the tripid field which is how I link them in my app.
I have a form for the Trip and it's Items property is set to a Gallery that the user goes to first to select which trip they want to update. Next to the form on the same screen I have a Gallery for TripDetails and it's Items property is also set to the Gallery. I can easily update data in the Form by just using SubmitForm(TripForm2_3) but I want to also update the TripDetails.
I have put a button on the bottom of the screen and it's On Select property is:
Patch(TripDetails,
ForAll(Gallery6_4.AllItems As _item,
{ tripid: _item.tripid,
tripdate: DateValue(_item.DatePicker1_1.SelectedDate),
destination: _item.TextInput2_25.Text,
activity: _item.TextInput2_27.Text,
accomodation: _item.TextInput2_29.Text,
localcontact: _item.TextInput2_28.Text,
callintimes: _item.TextInput2_30.Text,
hoursworked: _item.TextInput2_31.Text
}
)
)
I can go the Gallery and make changes to the data but when I try to update by clicking the button my code is adding new data to the list instead of just updating the existing data, so if I had 5 rows in the Gallery after I click the button I end up with 10 rows - how can I just UPDATE and not create new (I thought it would only create new records if I used (Defaults)??
any help greatly appreciated
Hi @bobgodin ,
Yes if it is unrelated to this, a new post is the appropriate action.
thanks @WarrenBelz that has fixed the problem but now I seem to have another problem in my app - should I create a new post? thanks
Hi @bobgodin .
If you have the ID already in the Gallery, there is no need for any of that
Patch(
TripDetails,
ForAll(
Gallery6_4.AllItems As _item,
{
ID: _item.ID,
tripid: Value(_item.TextInput2_26.Text),
tripdate: DateValue(_item.DatePicker1_1.SelectedDate),
destination: _item.TextInput2_25.Text,
activity: _item.TextInput2_27.Text,
localcontact: _item.TextInput2_28.Text,
accomodation: _item.TextInput2_29.Text,
callintimes: _item.TextInput2_30.Text,
hoursworked: _item.TextInput2_31.Text }
}
)
)
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
MVP (Business Applications) Visit my blog Practical Power Apps
Patch(
TripDetails,
ForAll(
Gallery6_4.AllItems As _item,
With(
{
_ID:
LookUp(
TripDetails,
ID = Value(_item.ID.Text)
).ID
},
{
ID: _ID,
tripid: Value(_item.TextInput2_26.Text),
tripdate: DateValue(_item.DatePicker1_1.SelectedDate),
destination: _item.TextInput2_25.Text,
activity: _item.TextInput2_27.Text,
localcontact: _item.TextInput2_28.Text,
accomodation: _item.TextInput2_29.Text,
callintimes: _item.TextInput2_30.Text,
hoursworked: _item.TextInput2_31.Text
}
)
)
)
Hi @WarrenBelz I decided that I should actually add a textLabel into the Gallery for the ID field so did this and renamed it to "ID" and added a bit more code and its working now
I hadn't realised how tricky it can be to do a simple update - here's my updated code - is there anything superfluous in there now?:
thanks 🙂
Hi @WarrenBelz thank you for that - I copied and pasted your code exactly into my app and it accepted it without any red lines but when I ran it it came back with a "Network error using Patch function. The requested operation is invalid" and didn't update anything
Hi @bobgodin ,
Try and get th SP ID back (if you do not have it in the gallery already)
Patch(
TripDetails,
ForAll(
Gallery6_4.AllItems As _item,
With(
{
_ID:
LookUp(
TripDetails,
tripid = _item.tripid
).ID
},
{
ID: _ID,
tripdate: DateValue(_item.DatePicker1_1.SelectedDate),
destination: _item.TextInput2_25.Text,
activity: _item.TextInput2_27.Text,
accomodation: _item.TextInput2_29.Text,
localcontact: _item.TextInput2_28.Text,
callintimes: _item.TextInput2_30.Text,
hoursworked: _item.TextInput2_31.Text
}
)
)
)
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
MVP (Business Applications) Visit my blog Practical Power Apps
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.