cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
seadude
Memorable Member
Memorable Member

"Data source supplied to the function is invalid" error when Patching an Image

Scenario:

  • Create a Collection OnStart of app:
  • Collect(collection,
        {
         user:    " ",
         notes:  " ",
         image: " ",
         date:    " ",
         time:    " "
        })
  • User clicks "take picture" button
  • Image ("takenPicture") overlays the camera control with still image
  • User clicks "save picture"
  • The Patch code for "save picture" is:
  • Patch(collection,
        {image: takenPicture.Image})
  • The still picture (takenPicture.Image) is not Patched into the collection.
  • An error on the "save picture" button shows:
  • Screenshot from 2018-05-12 21-37-00.png
  • The Patch code is now underlined in red squiggles with the same error:
  • Screenshot from 2018-05-12 21-39-04.png

 

Why is this happening and how can I overcome it?

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
timl
Super User
Super User

Hi @seadude

 

The second argument to the Patch function needs to specify the record in the collection that you want to update.

 

Supposing that you want to update the first record (the record that you created in the OnStart of your app), the syntax you would use would look like this:

 

Patch(collection,
      First(collection),
      {image: takenPicture.Image}
)

View solution in original post

4 REPLIES 4
timl
Super User
Super User

Hi @seadude

 

The second argument to the Patch function needs to specify the record in the collection that you want to update.

 

Supposing that you want to update the first record (the record that you created in the OnStart of your app), the syntax you would use would look like this:

 

Patch(collection,
      First(collection),
      {image: takenPicture.Image}
)
seadude
Memorable Member
Memorable Member

This is a great solution @timl, thank you. Do you know of straightforward code that will Lookup a unique record ID and Patch into that record rather than the First?

 

This is a tough scenario that I often encounter and have to hack something together. Would be nice to see others' solutions and develop a standard myself.

 

Example:

  • Data Source:
    • Set a unique identifier in the table by:
      • SQL:
      • Excel:
      • Sharepoint:
  • Patch function which looks up unique identifier and patches record to correct column
    • Patch(Lookup(Sort(Filter(xyz)))

Thanks again!

Figured it out.

 

Needed to set a PK in the SQL Table then refresh Data Source for PowerApps to likey.

 

See @Anonymous's last reply here: https://community.powerapps.com/t5/Connecting-to-Data/The-first-argument-of-Remove-should-be-a-collection/m-p/93838/highlight/true#M1031

Hi @seadude

 

Apologies for not replying sooner. Glad you figured it out! For the benefit of anyone else reading this, the formula would look like this:

 

Patch(collection,
      Lookup(SQLDataSource, UniqueIDColumn=1234),
      {image: takenPicture.Image}
)

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,636)