web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Get variable when an a...
Power Apps
Suggested Answer

Get variable when an app loads

(1) ShareShare
ReportReport
Posted on by 194
Hello,  i have an app that is connected to a sharepoint list, and i need to get the ID for the record that loads by default when my app starts.  Basically, i am using the patch command to update my list when a i click on the save icon.
 
Patch(
    PooledPromotions,
    LookUp(
        PooledPromotions,
        ID = varID
    ),
    Candidate.Updates,
    Manager_1.Updates,
    Manager_2.Updates,
    Interview.Updates,
    Onboard.Updates
);
 
everytime i choose a new record from my gallery, i am updating varID with that records ID, so this is only a problem affecting what ever record is displayed for the first time when my app loads.  if i try to save that record with out first selecting it in the gallery, varID is blank and nothing happens. 
 
 
i have tried to set varID on both the OnStart property of my app, and in the OnVisible property of my screen, but with no success using; Set(varID,Gallery1_1.Selected.ID);
 
how can i get my variable to populate when my app starts, or if that isnt possible, how can i keep my form from filling in with the first record before 
 
Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at
    Hi Frac 
    What do you mean by "loads by default" ? If you are loading into a gallery or for, it will be the first item of whatever list you are referencing.
    Set(
       varID,
       First(ListName).ID
    )
    If you are filtering the gallery, it will be
    Set(
      varID,
    First( YourGalleryFilterHere ).ID

    )

     
    Please click Does this answer your question 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 a Like.
    MVP (Business Applications)     Visit my blog Practical Power Apps    Buy me a coffee
  • Frac Profile Picture
    194 on at
    @WarrenBelz would this go under the items property of my gallery?
     
    Set(
       varID,
       First(
            Sort(
                Filter(PooledPromotions,'Promotion Cycle' =Pool.Selected.Value
                ),
                Candidate.DisplayName
            ).ID)
    )
  • Wee Teck Profile Picture
    45 on at
    you can set it with the screen where the gallery is located where In the properties pane, find OnVisible.
  • Suggested answer
    Nandit Profile Picture
    1,568 Moderator on at
    Hi Frac,
     
    A simple solution to this would be Disabling your Save button if no item is selected in your gallery and if nothing is selected, you can also display a message "Select an item before making updates" something like this. This is the ideal way, cause the user should first select the item they wish to update. 
     
    DisplayMode of your Save button:
    If(IsBlank(VarID), DisplayMode.Disabled, DisplayMode.Edit)
    Visible property of the Text label:
    IsBlank(VarID)
    This way you can make the users avoid pressing Save without selecting a record. 
     
    Hope this helps.
     
    Kind regards, 
    Nandit
     
    If this answers your query, please mark this response as the answer.
    If its helpful, please leave a like. Thanks!
     
  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at
    Hi Frac
    Yes - that will get the first record - alsoNandit's idea will work, but that was not the question you asked.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard