Skip to main content

Notifications

Power Apps - Building Power Apps
Unanswered

Runtime Data not Populating properly

Posted on 27 Nov 2024 08:42:06 by 962
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:
  • Artur Stepniak Profile Picture
    Artur Stepniak 50 on 27 Nov 2024 at 10:37:02
    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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,137

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,813

Leaderboard