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 do I get the ID of...
Power Apps
Answered

How do I get the ID of the current open record on a form being editted?

(0) ShareShare
ReportReport
Posted on by 316

Hi,

I have two lists - main list and related list.  I have created a related field in the second list called IDRefSec which automatically gets populated with the ID from the main list.

When I open the record, I use the following code to locate the related record (in the Items property):

Iamglt_0-1613082812845.png

What I am now trying to do is patch the current open related record.  In my other screens, I reference the ID of the selected gallery, however because this record is not opened from a Gallery, I am not sure how to reference it, my code is as follows:

 

// With varSecRec collection
// Check if related record exists. If it does not, then patch as a new record
ClearCollect(
 varSecRec,
 Sort(
 NewEmployeeSecurity,
 ID,
 Descending
 )
);
If(
 IsBlank(
 LookUp(
 varSecRec,
 (IDRefSec = varCurrRecord)
 )
 ),
 Patch(
 NewEmployeeSecurity,
 Defaults(NewEmployeeSecurity),
 frmSecurityDetails.Updates;
 ),
 Patch(
 NewEmployeeSecurity,
 {ID = <<<<CURRENT OPEN RECORD BEING EDITED>>>>},
 frmSecurityDetails.Updates
 )
);
Set(
 varSaveStatus,
 "Saved"
)

 

Its the second patch command I am trying to get working.

Any help is always greatly appreciated.

Cheers,

Geoff.

Categories:
I have the same question (0)
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Iamglt

    If you do 

     First(Sort(NewEmployeeSecurity,ID,Descending)).ID

    It should give you the ID of the record that was patched last. 

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

    @Iamglt 

    You appear to be doing this in a Form.  

    My first question would be, why are you not just doing a SubmitForm on the form?

     

    However, since it is a Form, you will have set the Item property to some record.  It is that record that will have the ID of the current record.

     

    But as mentioned, what you are doing in your formula, the SubmitForm will take care of for you.

     

  • Iamglt Profile Picture
    316 on at

    Hi Drrickryp,

    I don't think that will work, what happens is a record is selected from the main gallery, and it opens a new screen which has two forms on it.  The from from the gallery is read only, while the form from the related list is in edit mode.  So if the form currently being edited is saved, what happens if that was not the last record patched?

    Cheers,

    Geoff.

  • Iamglt Profile Picture
    316 on at

    Hi Randy,

    Thanks for your reply, the related form has multiple Combo boxes on it so I will need to use the patch to get this working.

    Cheers,

    Geoff.

     

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

    @Iamglt 

    EditForms support comboboxes as well as all other controls.

    I would advise making sure you have the datacards set up properly and just let PowerApps do what it does best with EditForms and avoid any of the extra work of the formula you're trying to build.

     

    Since you are trying to Patch the Updates property of the Form, then that would assume you already have the comboboxes working properly for your comboboxes.

    In which case, doing a SubmitForm(frmSecurityDetails) is all you need.

     

    When you skip the submit and try to Patch, you lose the features of the form, and you introduce errors in your app or more work to be done.  One case in point...you are setting a varSaveStatus to "Saved", how do you know it is saved?  What if the Patch fails?  With the SubmitForm, you get a OnSuccess action.  In that OnSuccess you would put your setting of the variable, then you know it is saved.

     

    If you do a NewForm(frmSecurityDetails) when you are creating a new record, then the SubmitForm will handle creating one.  If you are doing an EditForm(frmSecurityDetails) then again, the SubmitForm will handle all the work for you.

     

  • Iamglt Profile Picture
    316 on at

    Hi Randy,

    Can you let me know what you mean by 'I would advise making sure you have the datacards set up properly'?  What do I need to do to set them up properly?  In all of my forms, the Comboboxes never saved their values back to SharePoint after I used a Submit form, so I used form updates (to save the non combo boxes) and just patched the Comboboxes manually.  Any pointers here would be greatly appreciated.

    Cheers,

    Geoff.

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

    @Iamglt 

    So, the thing is, you are using the .Updates property of the form.  If that is accurate and gives you the proper values you need, then you are already accounting for the comboboxes or anything else in your form.  So the SubmitForm would do what you need.  I did not see in your formula where you were patching comboboxes back to the list.

     

    Comboboxes and other controls are used all the time.  If the source of your information for the control is from your datasource list, then you can simply change the control type in the field editor.  If it is coming from another location, then you simply need to change the Items property of the control.  The only key to getting everything connected is to make sure the Update is providing the value you want for your list (the same thing you have in any patch formula you are doing for them on the side) and getting the Default items properties set properly to display any value in an existing records.

     

    There is a WIDE variety of scenarios so it is hard to just pinpoint one and have it even remotely meaningful to your scenario.  If you have a specific combobox/field type that you have had difficulty with, I'd be happy to expand on the mechanics of it for you as I can assure you, using the features of the EditForm will significantly reduce your formulas, work, errors and headaches. 

     

    I have a video that covers all of the mechanics of EditForms (and a lot more then many know about using them).  It's a long video, but covers all the basics of the form in depth.  I don't cover specific controls in the form like putting comboboxes in specially (I have a partially finished video on that one).  Perhaps some scenarios from you will energize me to finish that video.

     

     

     

  • Iamglt Profile Picture
    316 on at

    Ok, I understand the relationship between the DataCard Update property and the Combobox DefaultSelectedItems property now.  For anyone else out there, the ComboBoxes and Dropdown lists do not work like MS Access (where values automatically get written back to data tables), they have to be configured manually:

     

    Configure DataCard Update property to write back to SharePoint field:

    Iamglt_0-1613088709554.png

    If all of your Comboboxes values disappear after a form submit (but the normal fields still retain their values), then you can get the Comboboxes to retain their values by updating the ComboBox DefaultSelectedItems property:

    Iamglt_1-1613088910264.png

    Cheers,

    Geoff.

     

     

     

  • Iamglt Profile Picture
    316 on at

    Hi Randy, big thanks for your help here.  I think we were both typing at the same time.  You are correct - I should have configured my DataCards /  ComboBoxes correctly, then the patching on my other forms would have been unnecessary.  I keep relating Comboboxes back to MS access, and I now see why we have DataCards (due to different data sources) so configuring Data Cards and ComboBoxes makes sense now.  I will watch your video later today.  I have a lot of work to do unpatching and setting up data cards properly in all of the other forms in my app.

    Cheers,

    Geoff.

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

    @Iamglt 

    Ah yes...the days of Access!!!  Try not to think "Access" in PowerApps - think "Excel" (it was modeled after it).

    Yeah, check out the video.  Grab a couple of energy drinks first...lol.  It's long, but it has a ton of stuff in it and the last two parts have been an eye-opener for many.

     

    Glad to get you rollin'

     

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 335 Most Valuable Professional

#2
11manish Profile Picture

11manish 166

#3
sannavajjala87 Profile Picture

sannavajjala87 71 Super User 2026 Season 1

Last 30 days Overall leaderboard