Skip to main content
Community site session details

Community site session details

Session Id : aha/UFOFCizGCZYiP8VMvg
Power Apps - Building Power Apps
Answered

Global variable to store Sharepoint Item ID won't update on OnStart or OnVisible

Like (0) ShareShare
ReportReport
Posted on 22 Oct 2023 13:06:55 by 21

Hi, I have a Powerapp linked to a Sharepoint list. I want to store the ID of the selected item (where applicable) to a Global Variable, but nothing works

 

I have tried: 

OnStart

=>If(MyForm.Mode=FormMode.New,Set(vClaimID,Blank()),Set(vClaimID,Int(IdValue.Text)))

I figured the landing screen (where the item's ID control is) not having loaded yet at OnStart, I'd have better chances using:

=>If(MyForm.Mode=FormMode.New,Set(vClaimID,Blank()),Set(vClaimID, SharePointIntegration.SelectedListItemID))

=>If(MyForm.Mode=FormMode.New,Set(vClaimID,Blank()),Set(vClaimID, SharePointIntegration.Selected.ID))

Outcome: the global variable is either blank or =1

 

Next, I tried variations of all of the above in the OnVisible property of my app's landing screen. All failed.

I then moved on to: 

=> creating a hidden button within the EditForm. The button's OnSelect property was set as follow: Set(vClaimID,Int(IdValue.Text))

=> ditto with:

Set(vClaimID,SharePointIntegration.SelectedListItemID) or 

Set(vClaimID, SharePointIntegration.Selected.ID) or  

Set(vClaimID,Int(varLabel.Text))

 

I then tried all of the above with a 3 second timer to delay the time the variable gets set and ensure the form had time to load.

 

All the while, the label I've created to display the item's ID (Text = IdValue.Text) displays the row ID correctly...

 

Finally, I tried loading that one piece of information into a collection, both on OnStart and OnVisible

ClearCollect(MyCollection,ShowColumns(Filter(MyDataSource, ID=SharePointIntegration.SelectedItemID),"ID"))

ClearCollect(MyCollection,ShowColumns(Filter(MyDataSource, ID=SharePointIntegration.Selected.ID),"ID"))

Played with a number of variations on "OnVisible", such as using a label to get the ID

ClearCollect(MyCollection,ShowColumns(Filter(MyDataSource, ID=Int(VarLabel.Text)),"ID"))

and other variations on the theme....

The collection remains empty.

 

Yes, I ran OnStart after every change.

 

Also tried with Set(vClaimID, ClaimForm.LastSubmit.ID), however Submit only works if changes have been made, so -even if I set a button to automatically select the button and submit the form at the OnVisible stage - nothing would have changed so no ID would be returned.

 

The only time the variable populates is when navigating away from the screen and navigating back to it, thus forcing OnVisible to run once more.

 

Stumped. I must be missing something really obvious.

There's no way something as basic as loading a row ID into a global variable when the app/screen loads would be  that much work.

 

Also tested using a context variable instead: same thing.

Only works if I navigate away from & then back to that screen.

 

Thanks in advance! 

  • Verified answer
    LiOtto Profile Picture
    21 on 22 Oct 2023 at 14:12:47
    Re: Global variable to store Sharepoint Item ID won't update on OnStart or OnVisible

    right, I have a working (but pathetic!) solution:

     

    I created a loading screen, set the Sharepoint OnView property to Navigate(LoadingScreen).

    That loading screen has got a hidden timer that auto-runs (3 seconds) and the  OnTimerEnd property is set to Navigate(ClaimScreen).

     

    When the ClaimScreen loads, both Global & Context variable update as expected.

     

    I do hope someone will suggest a less clunky solution...

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473

Loading complete