cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Smile1
Regular Visitor

PowerApps SharePoint Integration: Global variable

Hello friends,

I have an issue. I have a list on the SharePoint Site that looks:

Smile1_0-1601279329934.png

Then I have tried to customize Edit Form on PowerApps that uses a global variable for the SharePointIntegration.Selected record.

I have added the following code OnEdit event of SharePointIntegration component:

Smile1_4-1601280031707.png

And OnCancel event:

Smile1_5-1601280110221.png

On the screen, I have a form that uses the SharePointIntegration.Selected record as Item

Smile1_6-1601280216809.png

And a label that uses the variable

Smile1_7-1601280281332.png

(All the following photos contain a part of the SharePoint list on the left side and custom PowerApps in Edit mode on the right)

And then when I open the form on the SharePoint first time everything works well

Smile1_1-1601279510919.png

Then I close the form and try to open it for another record and it works for but not for my variable.

Smile1_2-1601279574803.png

If I open third time another record the form works but a variable shows me the second record.

Smile1_3-1601279688569.png

So, do you happen to know how to set a global variable properly?

(I understand that I may use the SharePointIntegration.Selected record for the label as well but my purpose is to use this record for setting other variables)

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-siky-msft
Community Support
Community Support

Hi @Smile1 ,

 

Yes, I can also reproduce your issue, and can't find out the reason of this issue for the time being.

However, here is another workaround, change to use LookUp function to retrieve back the record upon the 'SharePointIntegration.SelectedListItemID', rather than 'SharePointIntegration.Selected'.

Please try to modify the code as follows.

Set(
    SelectedWorkflow,
    If(
        IsBlank(SharePointIntegration.Selected) || IsEmpty(SharePointIntegration.Selected),
        First([@'SP list']),
        LookUp('SP list',ID= SharePointIntegration.SelectedListItemID)
    )
);

Hope this helps.

Sik

View solution in original post

5 REPLIES 5
v-siky-msft
Community Support
Community Support

Hi @Smile1 ,

 

Yes, I can also reproduce your issue, and can't find out the reason of this issue for the time being.

However, here is another workaround, change to use LookUp function to retrieve back the record upon the 'SharePointIntegration.SelectedListItemID', rather than 'SharePointIntegration.Selected'.

Please try to modify the code as follows.

Set(
    SelectedWorkflow,
    If(
        IsBlank(SharePointIntegration.Selected) || IsEmpty(SharePointIntegration.Selected),
        First([@'SP list']),
        LookUp('SP list',ID= SharePointIntegration.SelectedListItemID)
    )
);

Hope this helps.

Sik

Thanks, it works.

It works perfectly except for the first-time run (I guess it is related to App initialization. tried the same code-snippet in the App OnStart, but unfortunately didn't make any difference. still brings the 

First([@'SP list'])

 as a result and not the SharePoint selected item.

Any suggestions please, am really tired of this bug, been days now, and my form is quite complex enough

 

Curious - did you ever find a solution to fix the first run?

samstarzy
Advocate IV
Advocate IV

I am having a similar problem. I have tried to set a global variable (Boolean: E.G. varNewForm = true) to capture when the form is new vs. when it is being edited. PowerApps defaults to an "Edit" form mode, regardless of the form being started as "New", so this is my attempt at a workaround.

When I open a New form, the variable is set to "true" correctly. However, when I then open an item to "Edit", the variable does not get set the first time. Then when I open the item again, the variable does get set to "false". I do not understand why my code will run the second time, but not the first. Very frustrating. 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (1,192)