web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch Collection Issue
Power Apps
Unanswered

Patch Collection Issue

(0) ShareShare
ReportReport
Posted on by 792

Hi Community

I have just added a Latitude and longitude text box to a form and have tied them to two separate collections. The form is an edit form.
I am using patch to pass back all my data and want to patch the two collections to the selected item however I seem to be facing some issues with this

What I have written in my patch code:
Patch(DatabaseName, GALLERY.Selected,{Latitude:colLatitude})

Collect Code:
ClearCollect(LATITUDE, {Value: ThisItem.'Latitude'}); ClearCollect(LONGITUDE,{Value: ThisItem.'Longitude'})

The ClearCollect function works as expected but the patch element isn't?

Categories:
I have the same question (0)
  • Mx81 Profile Picture
    860 on at

    Maybe only a naming problem?

     

    Your Collection is named "LATITUDE", but your patching "colLatitude".

  • Kmayes Profile Picture
    792 on at

    Sorry that was a typo on my part, they are both the same

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Kmayes 

    I am not completely sure why you would be using a Collection for this.  Collections are in app databases with add and remove row capabilities.  There is certainly no reason to use one to assign a single value. 

    You could use a variable instead, but I suggest that you already have the value on the screen...why not just use it?

    You cannot set a column to an entire collection like you are in your formula.

     

    So, first, I am assuming that ThisItem.Latitude refers to a column in GALLERY

     

    If so, then your formula would be the following: 

    UpdateIf(DatabaseName, ID=GALLERY.Selected.ID, {Latitude: ThisItem.Latitude})

     

    If your Latitude value is in some other place, then get rid of the collections and set a variable.

    Set(glbLatitude, Thisitem.Latitude); Set(glbLongitude, ThisItem.Longitude)

    Then set your Patch formula to the following:

    Patch(DatabaseName, GALLERY.Selected,{Latitude: glbLatitude})

     

    Stay away from collections unless you really need an in-app version of a datasource.

     

    I hope this is helpful for you.

  • Kmayes Profile Picture
    792 on at

     

    The only niggle I have with this is, if the user edits the item again but doesnt set the variable it will now update the variable with a blank value. So I changed the variable to:

    Set(glbLatitude,If(ThisItem.'Valve Latitude'=Blank(),'VALVE LATITUDE VALUE'.Text,ThisItem.'Valve Latitude')); Set(glbLongitude,If(ThisItem.'Valve Longitude'=Blank(), 'VALVE LONGITUDE VALUE'.Text,ThisItem.'Valve Longitude')) 

    However it is not overwriting if the variable is reset, Have I just written this slightly wrong?

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Kmayes 

    So your formula can be this:

    Set(glbLatitude, Coalesce(ThisItem.'Valve Latitude', 'VALVE LATITUDE VALUE'.Text)); 
    Set(glbLongitude, Coalesce(ThisItem.'Valve Longitude', 'VALVE LONGITUDE VALUE'.Text))

     

    But, you mention this is in an EditForm, so really there is no need for the variable either.

    Your DataCard (not the control) for the Lat and Lon should have this in the Default property. 

    For example, the Lat datacard default should be:

    Coalesce(ThisItem.'Valve Latitude', 'VALVE LATITUDE VALUE'.Text)

    Same for the Lon datacard.

    If you are simply displaying that in a label in your datacard (not sure how you are using this in your datacard), then you can set the Text property of the label to : Parent.Default

    And finally, your Update property of the Datacard should be either Parent.Default or label.text (or whatever control you have in the datacard).

     

    That will give the Edit ability with retaining the original value and also adding the new value if none exist.

     

  • Kmayes Profile Picture
    792 on at

    The set up of the application is that data is in a datasoure and the person using the application can go to the site and edit the 'item' which they select through a gallery. The user has different parts of the form to complete so they may edit parts of the form while at the location then complete another part of the form when away from site.

     

    I need the ability for them to set the location details (when at site) that are then patched back to the item in the database. Therefore when away from site I do not want the user to overwrite the correct location details captured at site with a blank value. Therefore I cant just use the default value.

    However I think you're right in regards to the datacard default where maybe this needs to be set rather than a variable?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 483

#2
WarrenBelz Profile Picture

WarrenBelz 399 Most Valuable Professional

#3
11manish Profile Picture

11manish 327

Last 30 days Overall leaderboard