cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Super User
Super User

Different behavior between Studio and Published App

Help! I am experiencing different results when I run an app in studio and then immediately turn around and run the published copy of it.  I know I am running the same version because if I try to publish, it shows that the version I just ran in studio is already published.

 

When I run it in studio, it behaves correctly.  There is one record for me in a Sharepoint list.  It finds that record and displays it.  There are several debug fields at the bottom of the screen to try to help me figure out what is happening.  You will notice that CheckLoad is 1.  This is a row count of the number of times my email address appears in the collection which populates the gallery.  You'll also see CountRows is 1, which is the check used to determine if there are any records present for me.  When 0, it will add a record for me.    The code in the OnStart and the OnVisible of the home page are both at the bottom of this message. 
So, to reiterate, when I run this in studio, I get the result I would expect to see. 

THIS SCREEN SHOT FROM INSIDE STUDIO.

g1.png

 

When I run the app outside of studio, it is patching a new record every time in error.  What seems to be happening is the OnVisible of the HomePage is executing BEFORE the OnStart is executing.  I can tell this based on a couple things:

1.  The home page initially opens with no record displayed.  The Debug Message "About to Patch ResourcesDev" then populates almost immediately and the gallery then shows one record - the record it just told me it as about the patch.

2.  AFTER THIS, the CheckLoad value (which is set so I can debug near the end of the OnStart) populates and is set to 2 because it is now loading both the original record that was already there and should have loaded and the newly patched record.  

 

THIS SCREENSHOT IS FROM OUTSIDE STUDIO and shows the wrong behavior. with two records instead of one.

g2.png


Question:  Shouldn't the OnStart be completing before the OnVisible of the default screen starts - the behavior seen in Studio?  I thought for a minute the issue it might be due to the fact I had the load of the collection in OnStart inside a concurrent but I moved it out and the behavior is the same.  

 

Here's the related code from the OnStart, OnVisible of the default screen, and the Gallery (although that isn't really the source of the problem).

 

OnStart:

Set(
    CurrentUserEmail,
    User().Email
);

ClearCollect(colResources, ResourcesDEV);
ClearCollect(colCopyResources, ResourcesDEV);
ClearCollect(colRoster, ConsultingRoster);
Set(CheckLoad, CountRows(Filter(colResources, Email4Resource = CurrentUserEmail)));
ForAll(colCopyResources,
    Patch(colResources,  
    First(Filter(colResources, ID = ID)), 
    {ConsultantCountry : LookUp(colRoster, Email4Resource = ConsultantEmail).CountryName,
     ConsultantLocation: LookUp(colRoster, Email4Resource = ConsultantEmail).LocationHierarchy,
     ConsultantPractice: LookUp(colRoster, Email4Resource = ConsultantEmail).Practice,
     ConsultantSubpractice: LookUp(colRoster, Email4Resource = ConsultantEmail).Subpractice,
     ConsultantRole: LookUp(colRoster, Email4Resource = ConsultantEmail).Role,
     ConsultantRegion: LookUp(colRoster, Email4Resource = ConsultantEmail).RegionName
    })
);
   

I have only provided the portion of the OnStart that deals with the Resources list -- there is a lot more in the OnStart setting up other collections.  You'll notice where the CheckLoad debug value is set.  I can provide the rest if needed, but it all deals with other collections.

 

OnVisible of HomePage:

Set(PopUpVisible1, false);
If(RMAdmin = "Global", Set(AskRegion, true), Set(AskRegion, false));

If(IsBlank(CurrentUserEmail),Set(CurrentUserEmail, User().Email));

If(Demo3, 
    Set(CurrentUserEmail, "Steve.Schutter@teradata.com");
    Set(CurrentUserName, "Steve Schutter");
    Set(CurrentUserDisplayName, "Schutter, Steve");
    Set(IsRM, false);
    Set(RMAdmin, ""));

If(MgrAsIndividual, 1=1,
    !IsRM, 
    ClearCollect(DirectReports,Office365Users.DirectReportsV2(CurrentUserEmail).value);
    If(CountRows(DirectReports) = 0, 
        Set(IsMgr, false);
        If(CountRows(Filter(colResources, Email4Resource = CurrentUserEmail)) = 0, 
            Set(UserDetails, LookUp(ConsultingRoster, ConsultantEmail = CurrentUserEmail));
            If(IsBlank(UserDetails.RegionName),Set(PopUpVisible1, true);Reset(txtQLID),
            Set(DebugMsg, "About to patch ResourcesDev");
            //* Patch in the new item in the Sharepoint List
            Patch(ResourcesDEV, Defaults(ResourcesDEV),{Title: CurrentUserDisplayName, Email4Resource: CurrentUserEmail, LastUpdateDate: Today(), QuicklookID: UserDetails.Title,
                ConsultantCountry: UserDetails.CountryName, ConsultantPractice: UserDetails.Practice, ConsultantSubpractice: UserDetails.Subpractice, 
                ConsultantRole: UserDetails.Role, ConsultantRegion: UserDetails.RegionName, ConsultantLocation: UserDetails.LocationHierarchy});
            //* Then patch a copy into the collection which has already been loaded
            Patch(colResources, Defaults(colResources),{Title: CurrentUserDisplayName, Email4Resource: CurrentUserEmail, LastUpdateDate: Today(), QuicklookID: UserDetails.Title,
                ConsultantCountry: UserDetails.CountryName, ConsultantPractice: UserDetails.Practice, ConsultantSubpractice: UserDetails.Subpractice, 
                ConsultantRole: UserDetails.Role, ConsultantRegion: UserDetails.RegionName, ConsultantLocation: UserDetails.LocationHierarchy});
            Set(SelectedEmail, CurrentUserEmail);
            Set(SelectedName, CurrentUserName);
            Reset(txtQLID));
            Set(UserFound,true),
            Set(UserFound,true)
        ),
        //* Do not include indirect reports (toggle set to No)

        togIndirect.Value = false,
            ClearCollect(AllReports, DirectReports);
            Set(IsMgr, true),
            
        //* Include indirect reports is set to true  (toggle set to yes)   
            Clear(IndirectReports);
            Set(IsMgr, true);
            ClearCollect(AllReports, DirectReports);
            ForAll(
                AllReports, 
                Collect(IndirectReports, Office365Users.DirectReportsV2(mail).value)
            );
            Set(NumFound, CountRows(IndirectReports));
            If(NumFound = 0, 1=1,
                Collect(AllReports,IndirectReports);
            )
    )
);
If(IsRM, Set(LimitRegion, RMRegion),Set(LimitRegion, LookUp(colResources, Email4Resource = CurrentUserEmail).ConsultantRegion));
If(LimitRegion = "Global", 
ClearCollect(
    colCountries,
    Sort(
        RenameColumns(
            ShowColumns(
                Filter(
                    Distinct(ConsultingRoster,CountryName),
                    Result <> ""
                ),
                "Result"
            ),
            "Result",
            "CountryName"
        ),
        CountryName
    )
),
ClearCollect(
    colCountries,
    Sort(
        RenameColumns(
            ShowColumns(
                Filter(
                    Distinct(
                        Filter(
                            ConsultingRoster,
                            LimitRegion = RegionName
                        ),
                        CountryName
                    ),
                    Result <> ""
                ),
                "Result"
            ),
            "Result",
            "CountryName"
        ),
        CountryName
    )
));
Patch(
    colCountries,
    Defaults(colCountries),
    {CountryName: " None selected"}
);
Clear(colCountryNGeo);
Collect(
    colCountryNGeo,
    colCountries
);

If(ReturnfromDetail, 1=1,
    Reset(txtName);
    Reset(txtCountry);
    Reset(txtKeyword);
    Reset(txtRole);
    Reset(txtPractice);
    Reset(txtSubpractice),
    Reset(txtArea);
    Reset(txtLocation);
    Reset(txtClearance);
    Reset(ddCitizenship);    
    Set(ReturnfromDetail, false));

The following values used in the OnVisible have been confirmed with debug labels.

IsMgr is false.
RMAdmin is blank

IsRM is false

MgrAsIndividual is false.
Demo3 is false.

 

And finally, the gallery code which falls down to the last 4 lines, based on the values of the global variables just provided.

If((IsRM && RMAdmin = "Global" && ddAskRegion.Selected.Value <> "Per Profile") || 
    (IsRM && RMAdmin = "Region" && togPerProfile.Value = false) ||
    (IsRM && togExpandSearch.Value = true), 
    SortByColumns(
        AddColumns(
            Filter(AddColumns(colResources, "ConsultantArea",
            If(Left(ConsultantCountry,13) = "United States" && IsBlank(ConsultantLocation), "AMS North America", Left(ConsultantCountry,13) = "United States",
                    LookUp(colGeo, ConsultantLocation = d0rf && ConsultantRegion = Title).Geo,
                    LookUp(colGeo,ConsultantCountry = Geo && ConsultantRegion = Title).Area)), 
                RMRegion = ConsultantRegion,
                If(IsBlank(txtName.Text), 1=1, txtName.Text in Title || Upper(txtName.Text) in Upper(QuicklookID)),                              
                If(txtArea.Selected.Result = " None selected", 1=1, 
                     ConsultantLocation in Filter(Filter(colGeo,txtArea.Selected.Result = Area).d0rf,!IsBlank(d0rf)) || 
                     ConsultantCountry in Filter(colGeo,txtArea.Selected.Result = Area).Geo),     
                If(txtCountry.Selected.CountryName = " None selected", 1=1, ConsultantCountry = txtCountry.Selected.CountryName) || 
                    (!IsBlank(ConsultantLocation) && ConsultantLocation in Filter(colGeo,txtCountry.Selected.CountryName = Geo).d0rf), 
                If(txtLocation.Selected.Result = " None selected", 1=1, ConsultantLocation = txtLocation.Selected.Result), 
                If(txtPractice.Selected.Result = " None selected", 1=1, ConsultantPractice = txtPractice.Selected.Result),
                If(txtSubpractice.Selected.Subpractice = " None selected" || IsBlank(txtSubpractice.Selected.Subpractice), 1=1, 
                     ConsultantSubpractice = txtSubpractice.Selected.Subpractice),
                If(txtRole.Selected.Role = " None selected", 1=1, ConsultantRole = txtRole.Selected.Role),
                If(IsBlank(txtKeyword.Text),1=1, txtKeyword.Text in Keywords),
                If(ddCitizenship.Selected.CountryName = " None selected", 1=1, ddCitizenship.Selected.CountryName in Citizenship),
                If(IsBlank(txtClearance.Text),1=1, txtClearance.Text in Clearance)), 
        "FirstName", Mid(Title,Find(" ",Title) + 1),
        "LastName",Left(Title,Find(" ", Title) - 2)),
    "LastName"),
    IsRM, 
    SortByColumns(
        AddColumns(
            Filter(AddColumns(colResources, "ConsultantArea",
               If(Left(ConsultantCountry,13) = "United States" && IsBlank(ConsultantLocation), "AMS North America", Left(ConsultantCountry,13) = "United States",
                    LookUp(colGeo, ConsultantLocation = d0rf && ConsultantRegion = Title).Geo,
                    LookUp(colGeo,ConsultantCountry = Geo && ConsultantRegion = Title).Area)), 
                RMRegion = ConsultantRegion,
                If(ContainsSpecial, 1=1, Left(ConsultantCountry,13) = "United States", ConsultantArea in colGeoFilter.RMGeo, ConsultantCountry in colGeoFilter.RMGeo),
                If(IsBlank(txtName.Text), 1=1, txtName.Text in Title || Upper(txtName.Text) in Upper(QuicklookID)),                           
                If(txtArea.Selected.Result = " None selected", 1=1, 
                     ConsultantLocation in Filter(Filter(colGeo,txtArea.Selected.Result = Area).d0rf,!IsBlank(d0rf)) || 
                     ConsultantCountry in Filter(colGeo,txtArea.Selected.Result = Area).Geo),     
                If(txtCountry.Selected.CountryName = " None selected", 1=1, ConsultantCountry = txtCountry.Selected.CountryName) || 
                    (!IsBlank(ConsultantLocation) && ConsultantLocation in Filter(colGeo,txtCountry.Selected.CountryName = Geo).d0rf), 
                If(txtLocation.Selected.Result = " None selected", 1=1, ConsultantLocation = txtLocation.Selected.Result), 
                If(txtPractice.Selected.Result = " None selected", 1=1, ConsultantPractice = txtPractice.Selected.Result),
                If(txtSubpractice.Selected.Subpractice = " None selected" || IsBlank(txtSubpractice.Selected.Subpractice), 1=1, 
                     ConsultantSubpractice = txtSubpractice.Selected.Subpractice),
                If(txtRole.Selected.Role = " None selected", 1=1, ConsultantRole = txtRole.Selected.Role),
                If(IsBlank(txtKeyword.Text),1=1, txtKeyword.Text in Keywords),
                If(ddCitizenship.Selected.CountryName = " None selected",1=1, ddCitizenship.Selected.CountryName in Citizenship),
               If(IsBlank(txtClearance.Text),1=1, txtClearance.Text in Clearance)), 
        "FirstName", Mid(Title,Find(" ",Title) + 1),
        "LastName",Left(Title,Find(" ", Title) - 2)),
    "LastName"),
    IsMgr,
        SortByColumns(
            AddColumns( 
                    Filter(colResources,
                        Email4Resource in AllReports.userPrincipalName || Email4Resource in AllReports.UserPrincipalName,
                        !IsBlank(Email4Resource),
                           If(IsBlank(txtName.Text), 1=1, txtName.Text in Title || Upper(txtName.Text) in Upper(QuicklookID)),
                        If(IsBlank(txtKeyword.Text),1=1, txtKeyword.Text in Keywords)),
            "LastName", Mid(Title,Find(" ",Title) + 1),
            "FirstName",Left(Title,Find(" ", Title) - 1)),
        "LastName"),
    AddColumns( 
        Filter(colResources,Email4Resource = CurrentUserEmail),
        "LastName", Mid(Title,Find(" ",Title) + 1),
        "FirstName",Left(Title,Find(" ", Title) - 1))
)

You can see where DebugMsg (displayed in the debug labels on the Home Page) is set.  This is populating BEFORE CheckLoad in the OnStart is populating. 

 

Why is this happening at all?  Why is it happening when the app runs for real but not in studio?   How do I get it to work correctly -- as it does in Studio?

 

I'm happy to share any other screen shots anyone might want or to capture video in Camtasia and post to better demonstrate what is happening.  

 

Thanks in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Different behavior between Studio and Published App

@LRVinNC 

Hey there!

Have you checked your Advance settings option for "Use non-blocking OnStart rule".  If you have that set on (which is default), it will run OnStart in parallel with other actions.  If off, the app will wait for the OnStart to complete.

See if that is helpful.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

3 REPLIES 3
Super User
Super User

Re: Different behavior between Studio and Published App

@LRVinNC 

Hey there!

Have you checked your Advance settings option for "Use non-blocking OnStart rule".  If you have that set on (which is default), it will run OnStart in parallel with other actions.  If off, the app will wait for the OnStart to complete.

See if that is helpful.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

Super User
Super User

Re: Different behavior between Studio and Published App

Many thanks Randy.  No, I was not conscious of that setting and it was indeed the problem.  I see a new blog topic being written on this tonight.  Again, my thanks.

Highlighted
Super User
Super User

Re: Different behavior between Studio and Published App

@LRVinNC 

Always happy to help...sorry I've been so distant from the forum over the past couple months.  Major project on the plate is finally coming to a close, so hopefully I'll have some more "answering" time shortly.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (4,710)