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