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 / Form, check if item ex...
Power Apps
Answered

Form, check if item exists if not create new.

(0) ShareShare
ReportReport
Posted on by 6

I have a button on the loading page that when selected should do some things:

 

  1. Check if an item has been created in the Sharepoint list by the user. We want only one entry in the list per user. 
  2. Navigate to the page with the form.
  3. Set the form on the page to 'new' if a record created by the user does not exist, or set the form to 'edit' and populate with the record if an item has already been created by the user.

 

I found a Post that seems to do exactly what I want to do : https://powerusers.microsoft.com/t5/Building-Power-Apps/check-if-item-exists-if-not-create-new-using-button-to-navigate/m-p/579778#M181063

 

However the code does not work for me. I think I have changed the appropriate parts for my app. However I get an "invalid argument type" error message. I can not figure out what is invalid. 

 

My code: 

 

Set(recordID, LookUp(SP_List,Variable='Created By'.Email, ID));
If(IsBlank(recordID),NewForm(Form1), EditForm(Form1));
Navigate(MyForm);

 

Anyone have any ideas what I am doing wrong?  

Categories:
I have the same question (0)
  • Verified answer
    faustocapellanj Profile Picture
    1,662 on at

    Hi @Bryon 

    This code should work. Here's the approach I would take re-using the code from the post you found. I would run the first line of code below in the App OnStart:

    Set(varUser, User());


    Run the code below on the button:

    Set(varRecord, LookUp(YourSharePointListName, 'Created By'.Email = varUser.Email));
    
    If(IsBlank(varRecord), NewForm(YourFormName), EditForm(YourFormName));
    
    Navigate(YourFormScreen);

     

    For the Form's Item property, set its value to the varRecord variable. No need to do the LookUp because the LookUp performed to set the varRecord variable is pulling the entire record and not just the record ID like in the example you listed.

     

  • Bryon Profile Picture
    6 on at

    @faustocapellanj 

     

    Thank you. I appreciate the help. 

     

    Your suggestions have solved the invalid argument errors. However the process does not seem to be working. I think the form mode is not changing even though there is a record created by the user in the list. 

     

    I have gone through the app to see if I had something else setting the form mode and can not find anything. I have even set the form default mode to blank.

     

    Is there a way to check the variables and see what they are getting populated with?  Is there a way to step through the app? Maybe I should use something other than Email address to identify the users? 

     

    I am not a programmer and this is my first Power App so I could be making very basic mistake. 

     

     

  • faustocapellanj Profile Picture
    1,662 on at

    Hi @Bryon 

    Here's a way you can test the variables. Insert a couple of labels on any of the screens and set their Text property to the variable. To view the value of the varRecord variable, you will have to do something as follows: varRecord.ID because this variable contains multiple columns. Also, to check if the varRecord is empty, set the Text property of the next label to IsBlank(varRecord); this will show either true or false. Try that and let me know.

  • Bryon Profile Picture
    6 on at

    @faustocapellanj 

     

    Thank you for the pointers on how to check the variables. 

     

    Oddly I opened the app to start working on it today and it works as intended.  Not sure why as I changed nothing. 

     

    For now I thank you for your help. 

     

  • faustocapellanj Profile Picture
    1,662 on at

    Hi @Bryon 

    I'm glad to hear things are working now. Feel free to reach out with additional questions or a different project.

    Regards,

  • MichaelBoonie Profile Picture
    16 on at

    I know I'm two years too late, but this is as close to a description of my issue as I can find anywhere.

     

    In my case is that I am working on a customized SP List Form, not an app per se. (Nobody has mentioned whether they're using a List form or an app.) Nothing referenced in this thread seems to work even a little (except for getting the current user() info.) The  steps in the thread referenced in this one (which queries for records by matching ID) doesn't do anything, nor does trying to return a whole record as an object (referenced here.) Also, I can't use "Created by", since the same person may have created several requests on behalf of others; instead, I have a "Requestor" people control whose entry should be referenced when deciding to edit or create a new request.

     

    Is there an issue because I'm using an actual List Form (accessed from the list using the New button)? As I mentioned, nothing is being returned using the LookUp function, neither the record nor any property. Still, I need to look up and edit any existing record for the Requestor, or otherwise open a New one. I really can't have the user selecting their record from the list. (I don't even want them to SEE the list!) I want a URL that will either open a New form if the user() doesn't already have a record where they are already listed as the "Requestor."

     

    Is this possible with a customized List Form?

  • MichaelBoonie Profile Picture
    16 on at

    OK, so my assessment was wrong: I can indeed query and retrieve any existing records.

     

    The problem was that I was using email as a filter, and (at least at my company) the email property of user() is NOT necessarily the same as the email property of a People selector control. At my company, our "real" email is our company ID, but there is also a friendly email comprising our actual names. I had to parse the Claims property to compare apples to apples, and now it works.

     

    Sorry for the false alarm, but maybe this can help someone, too.

     

    -Boonie

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 542 Most Valuable Professional

#2
Haque Profile Picture

Haque 206

#3
Kalathiya Profile Picture

Kalathiya 201 Super User 2026 Season 1

Last 30 days Overall leaderboard