cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jharville
Helper V
Helper V

If user input also exists in SharePoint list's column, patch to existing record. If user input does not exist SharePoint list's column, create new record.

 

Hello!

 

Here is a screenshot of my application's initial landing screen, where the user types in a unique, 5-digit location # to search for (I save their user input text as a variable called "locNum") a location.

 

jharville_1-1652405634238.png

 

 

 

Here is a screenshot of my EditForm:

 

jharville_2-1652405634241.png

 

 

And lastly here is a screenshot of my SharePoint List:

 

jharville_3-1652405634242.png

 

 

Before filling out the EditForm, the SP List had 3 existing items: 04603, 00502, and 03413 ... Notice how in the original landing screen, the user typed in '00502'. And when I clicked the Submit button of my EditForm (using SubmitForm() function), it created that 4th item in the SP List that doesn't have a title. 

 

My question: If 00502 already exists in the SharePoint list (with no filled in attributes/column values) and the user types in '00502' in the initial landing screen (a match), how do I patch (or update) info from Edit Form to that existing SharePoint list record? And alternatively, if the user types in a 5-digit number in the landing screen that doesn't exist in the SharePoint list, create a new item registering their 5-digit number as the title of that new record?

 

I've tried this code but no luck so far... Thank you! 

 

jharville_5-1652405792897.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @jharville ,

Structure would be something like this

With(
   {
      wID:
	  LookUp(
         SPListName,
         Title = YourLocationTextBox.Text
      ).ID
   },
   Patch(
      SPListName,
      If(
         wID > 0,
         {ID:wID},
         Defaults(SPListName)
      ),
      {YourPatchedFieldsHere}
   )
)
   

 

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.

Visit my blog Practical Power Apps

View solution in original post

1 REPLY 1
WarrenBelz
Super User
Super User

Hi @jharville ,

Structure would be something like this

With(
   {
      wID:
	  LookUp(
         SPListName,
         Title = YourLocationTextBox.Text
      ).ID
   },
   Patch(
      SPListName,
      If(
         wID > 0,
         {ID:wID},
         Defaults(SPListName)
      ),
      {YourPatchedFieldsHere}
   )
)
   

 

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.

Visit my blog Practical Power Apps

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (3,883)