Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

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

(0) ShareShare
ReportReport
Posted on 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
    LiOtto 21 on at
    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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,508

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,839

Leaderboard