Skip to main content

Notifications

Power Apps - Building Power Apps
Suggested answer

Runtime Data not Populating properly

(0) ShareShare
ReportReport
Posted on by 986
Hi everyone,
I was facing one issue regarding run time data loading. To give you guys a better context I will explain the problem with the following example

Basically I have built Canvas App that users can use to raise request and this application has 4 roles: User, Manager, Admin and Infra. For Admin and Infra role I ham maintaining two separate SharePoint list named AdminList_VManagement and InfraTeam_VM bot these list have a Title column and Person type column



And for Manager details: I am referencing another list ManagerList_SM

(The above list is just used for referring a user's reporting manager)

In Power Apps to determine the Role I have designed the following expression:
Set(
    CurrentUserRole,
    If(
        //Team Center Admin
        CountRows(Filter(Admins,Administrator.Email = User().Email)) > 0, "Admin",
        //Infra Team
        CountRows(Filter(InfraTeam_VM,Member.Email = User().Email)) > 0, "Infra",
        //Manager
        CountRows(Filter(VMRequest,Manager = User().Email)) > 0, "Manager",
        "User"
    )
);

I have a request Overview screen that shows the request created (I have also added a constraint that user should only see the request that they have created
It looks something like: (All the request that you see are the one's that I have created )



On Gallery's Items property:
If(
    varSearchClicked && !IsBlank(SearchInput2_1.Value),
    Search(
        SortByColumns(
            Filter(
                VMRequest,
                (CurrentUserRole = "Admin" && (Status.Value = "In-Progress" || Status.Value = "VM-Granted" || Status.Value = "VM-Provisioning")) ||
                (CurrentUserRole = "Manager" && Status.Value = "In-Review" && Manager = User().Email) ||
                (CurrentUserRole = "Infra" && Status.Value = "VM-Provisioning") ||
                (CurrentUserRole = "User" && Email = User().Email),
                // Apply status filter only if varStatusSelected is not blank
                If(!IsBlank(varStatusSelected), Status.Value = varStatusSelected, true)
            ),
            "Created",
            varSortOrder
        ),
        SearchInput2_1.Value,
        Title
    ),
    // Default view if no search input or varSearchClicked is false
    SortByColumns(
        Filter(
            VMRequest,
            (CurrentUserRole = "Admin" && (Status.Value = "In-Progress" || Status.Value = "VM-Granted" || Status.Value = "VM-Provisioning")) ||
            (CurrentUserRole = "Manager" && Status.Value = "In-Review" && Manager = User().Email) ||
            (CurrentUserRole = "Infra" && Status.Value = "VM-Provisioning") ||
            (CurrentUserRole = "User" && Email = User().Email),
            // Apply status filter if varStatusSelected is not blank
            If(!IsBlank(varStatusSelected), Status.Value = varStatusSelected, true)
        ),
        "Created",
        varSortOrder
    )
)


And for the title text for different role: the text changes like for user the title text of the screen is: Request Overview ; for Manager role it is: Manager Dashboard for Request Overview so on the Text property I have set the following expression
//For Screen Title Text

If(
    CurrentUserRole = "User",
    "Request Overview",
    
    //For Manager and other roles:
    If(
        CurrentUserRole = "Manager",
        "Manager View for: " & "Request Overview",

        //For Admin and Infra:
            If(
                CurrentUserRole = "Admin",
                "Admin View for: " & "Request Overview",
                "Infra View for: " & "Request Overview"
            )
    )

)

So recently I have observed that for other roles like Manager/Admin (all the changes were saved and published) sometimes the request Overview screen shows title: Infra View and the items in gallery is Blank, but after refreshing the page 1-2 times then it shows the data as expected. So to cross check I checked in the code (Edit mode) for the respective members in Manager and Admin role the value in currentUserRole was been set properly.

The below image is of Admin role: In Run Mode


To cross-check I asked the Admin role in the edit mode if the value in variable is been set properly or not and it was as expected:


And after refreshing the page 2-3 times then the data was shown properly as per the respective user role, to better understand this you can have a look at the GIF, you can get a clear picture of what I am referring to



I am not sure what is the issue at start it was working fine with no issues but since last week I came across this issue, I have not made any changes in my App On-start nor on Items property of the gallery that displays the request.
The gallery displays request from 'VMRequest' which is a SharePoint list that stores all the request it looks like:
  • Sidhant_02 Profile Picture
    Sidhant_02 986 on at
    Runtime Data not Populating properly
    Hi @Artur Stepniak,
    Sorry for the late reply don't get notifications of replies to the post that we used to earlier, saw your reply today after I had logged into the forum site.
    Delegation is an issue right now the data size is comparatively smaller but you never know it can grow as well.

    I had tried another approach using Lookup (instead of using CountRows and Filter), the expression was as follows:
    Set(
        
            CurrentUserRole,
            If(
                !IsBlank(LookUp(Admins, Administrator.Email = User().Email)),"Admin",
                !IsBlank(LookUp(InfraTeam_VM, Member.Email = User().Email)),"Infra",
                !IsBlank(LookUp(VMRequest, Manager = User().Email)),"Manager",
                "User"
    
            )
        
    );

    This worked at start in few cases but started to show the same behavior as my previous expression. I'm still unclear what's the case as the expression is alright and in edit mode as well when I cross-checked it works fine its just that somehow in run mode it starts causing an issue.

    Regards,
    Sidhant   
  • Suggested answer
    Artur Stepniak Profile Picture
    Artur Stepniak 1,359 on at
    Runtime Data not Populating properly
    Hello again,
     
    in case you have large tables, then it's worth to consider delegation limits: https://learn.microsoft.com/en-us/power-apps/maker/canvas-apps/delegation-overview.
    By "you could set the data source rows to the variable" I mean instead of referring to the data source directly (by '<DATA SOURCE NAME>'), you could create a variable with Set(dtVmRequests, '<DATA SOURCE NAME>') to have a local copy of data. But if your dataset is going to be large, it won't be efficent - you'd need to think on how to filter it out and show only necessary rows. 
     
    In case of any other questions, let me know. If the answer helped you, mark it, so that others can benefit from it.
     
    Best regards,
     
    Artur Stepniak
  • Sidhant_02 Profile Picture
    Sidhant_02 986 on at
    Runtime Data not Populating properly
    Hi @Artur Stepniak,
    Could you explain the second point that you mentioned in your last reply with an example (in my example context).
    The other point regarding how many rows I will have in my list for AdminList ad Infra list it will be limited like 4-5 max I guess but in case of the ManagerList and VMRequest it won't be the case the number will be large.

    Regards,
    Sidhant
  • Artur Stepniak Profile Picture
    Artur Stepniak 1,359 on at
    Runtime Data not Populating properly
    Hello,
     
    thanks for the response! Still I think that something is not being fetched correctly.
    What you could also try is to add/remove data sources.
    And the second option: you could set the data source rows to the variable, instead of referring to the data source directly.
    You can also implement a spinner to show until the data is fully loaded - maybe the issue is that it's being loaded for a long time?
    How many rows do you have on the list?
     
    Best regards,
     
    Artur Stepniak
  • Sidhant_02 Profile Picture
    Sidhant_02 986 on at
    Runtime Data not Populating properly
    Hi Artur Stepniak,
    I have set the property on the On-Start itself and then I am setting the value in my currentUserRole

     
    Regarding the value part in Edit mode when I checked with one of the user (Admin role) the variable was being set properly and they could see the data properly

    The suggestion that you have given:
    Each CountRows() output should be used as a separate variable. Then you can use Concurrent() to fetch everything in one go, can you explain this with an example

    Also I did try using nested If-Structure:
    Set(
        CurrentUserRole,
        If(
            //Team Center Admin
            CountRows(Filter(Admins,Administrator.Email = User().Email)) > 0, "Admin",
                If(
                //Infra Team
                CountRows(Filter(InfraTeam_VM,Member.Email = User().Email)) > 0, "Infra",
                    If(
                    //Manager
                    CountRows(Filter(VMRequest,Manager = User().Email)) > 0, "Manager",
                    "User"
                    )
                )
        )
    );
    That too has the same issue. In one of Mathew Devaney post for If-statement Multiple conditions


    So my current expression looks valid if it had issues than it should have thrown errors from start.
  • Artur Stepniak Profile Picture
    Artur Stepniak 1,359 on at
    Runtime Data not Populating properly
    Hello,
     
    where this code is implemented, in what property?
     
    Set(
        CurrentUserRole,
        If(
            //Team Center Admin
            CountRows(Filter(Admins,Administrator.Email = User().Email)) > 0, "Admin",
            //Infra Team
            CountRows(Filter(InfraTeam_VM,Member.Email = User().Email)) > 0, "Infra",
            //Manager
            CountRows(Filter(VMRequest,Manager = User().Email)) > 0, "Manager",
            "User"
        )
    );
     
    I think that the CurrentUserRole is not populated properly when the app is started. I'd suggest following:
     
    1. Each CountRows() output should be used as a separate variable. Then you can use Concurrent() to fetch everything in one go.
    2. Then you can Set() CurrentUserRole based on the output that you have.
     
    If it won't help, you can check the outputs of CountRows() and review the logic for filters in the gallery. What's also worth trying is to check how the filters for the gallery behave when they're set to the variable, instead of referring the data source directly.
    I'd also suggest to put the code in App.OnStart property, if it's not there yet.
     
    Best regards,
     
    Artur Stepniak
     
     

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,666

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,996

Leaderboard