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 / How to get newly creat...
Power Apps
Unanswered

How to get newly created record in a variable with patch and submitform

(0) ShareShare
ReportReport
Posted on by 12

I have a form and I am creating a new record in CDS, after creating I want to change form mode to edit and update the same record but when I change the mode to edit it shows no "Item to display" and it is due to form item property empty and it needs that newly created record but I do not know how to get that newly created record? How can we do this with patch and with submitform?

Categories:
I have the same question (0)
  • Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    as salaam mu alikom @MuzaffarMuhmood ,

     

    Apply the below to the OnSuccess property of your Form:

     

    Set(
     varRecord,
     Self.LastSubmit
    );

     

    In the example above, replace "varRecord" with the name of your variable.

     

    ------------------------------------------------------------------------------------------------------------------------------

     

    If I have answered your question, please mark your post as Solved. Remember, you can accept more than one post as a solution.

    If you like my response, please give it a Thumbs Up.

    Imran-Ami Khan

  • Mahmood Muzaffar Profile Picture
    12 on at

    Walaikum Mussalam @Amik 

    I am doing the same, but when I use later this varRecord in patch like this 

    Patch('User Scores', varRecord,{
    '1st Question': '1st Question_DataCard1'.Update,
    '2nd Question': '2nd Question_DataCard1'.Update,
    '3rd Question': '3rd Question_DataCard1'.Update
    });

    It gives the error "The specified column is read-only and can not be modified."

    I think the lastSubmit gives read-only fields like created on created by etc that are read-only. 

     

  • Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    @MuzaffarMuhmood - I assume you also have "varRecord" in the Item property of your Form?

     

    The Last Submit function will get the entire record that was just created or edited, and not just return the system fields. That is not how it works.

     

    I cannot recreate the issue you're experiencing. The only thing I do note is that in your initial post, you mention you change the Form mode to Edit. I do not see what the point of this is, the DefaultMode property for the Form should just be FormMode.Edit?

     

     

  • Mahmood Muzaffar Profile Picture
    12 on at

    Thank you @Amik 

    yes, varRecord is in the item property of the form. 

    on the app load form mode is new then onSelect on the save button I am submitting the form, setting form to edit mode with editform(formname), and setting item property of the form to formname.lastsubmit, hiding current fields and showing some other fields of the same record (kind of multi-step form), and then on the save button, I am submitting the form again. I am expecting an update of the same record. 

  • Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    Hi @MuzaffarMuhmood ,

     

    Could you confirm the following:

     

    On your New Form Button, you have:

     

    NewForm(Form1)

     

     

    On your Edit Form Button and/or on the OnSelect property of the Gallery (if you're using one), you have:

     

    Set(
     varRecord,
     ThisItem
    );
    EditForm(Form1)

     

     

    On the Submit Form button, you only have:

     

    SubmitForm(Form1)

     

     

    On the OnSuccess property of the Form, you have:

     

    Set(
     varRecord,
     Self.LastSubmit
    )

     

     

    If you’re going to Patch the same data source after the Submit Form procedure, you need:

     

    Set(
     varRecord,
     Self.LastSubmit
    );
    Set(
     varRecord,
     Patch(
     'User Scores',
     LookUp(
     'User Scores',
     ID = Form1.LastSubmit.ID
     ),
     {
     '1st Question': '1st Question_DataCard1'.Update,
     '2nd Question': '2nd Question_DataCard1'.Update,
     '3rd Question': '3rd Question_DataCard1'.Update
     }
     )
    )

     

     

    ------------------------------------------------------------------------------------------------------------------------------

     

    If I have answered your question, please mark your post as Solved. Remember, you can accept more than one post as a solution.

    If you like my response, please give it a Thumbs Up.

    Imran-Ami Khan

  • Mahmood Muzaffar Profile Picture
    12 on at

    Thanks @Amik 

    I was doing the same as you explained but there was another issue, some read-only fields like created on were there in the form as hidden and those were giving errors on updating the record.

    But I could not get

    Form1.LastSubmit.ID

     

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!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 551

#2
WarrenBelz Profile Picture

WarrenBelz 430 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 298

Last 30 days Overall leaderboard