cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
C_Baugher
Frequent Visitor

onStart - Collection Not Popualting

I seem to be running into an issue with my onStart - formula is below. When I run the onStart within the builder/editor (manually), it works perfectly. When I go ahead and have my test user run the app, it appears as though the collection is not populating. The table it is calling in SP is open to all my users with read access, and is only 115 rows, so I don't think I'm running into limits. When I run the monitor on the user it simply says 'success' but zero rows returned. I went ahead and turned off use non-blocking onstart rule as recommended in some other threads but the issue persists. I also tried throwing it on onVisible but the net result is the same. I'm basically just importing that to a local table to switch languages for folks.

 

 

// Set employee email to avoid delegation.
Set(
    employeemail,
    Lower(User().Email)
);
// Set today's date to avoid delegation.
Set(
    vartoday,
    Today()
);
// Import translation Table.
ClearCollect(
    TranslationTable,Translation
);
// Get Language and Set variable.
Set(
    userlang,
    Language()
);
// Language 2 letter code.
Set(
    userlangshort,
    If(
        "-" in userlang,
        Left(
            userlang,
            Find(
                "-",
                userlang
            ) - 1
        ),
        userlang
    )
);
// Final language code
Set(
    userlanguagefinal,
    Coalesce(
        LookUp(
            TranslationTable,
            userlangshort = Title
        ).Title,
        "en"
    )
);
// Load if available - response
ClearCollect(
    existingid,
    Filter(
        'FLHA Responses V2',
        employeemail = 'Created By'.Email And 'Submission Date' = Date(
            Year(vartoday),
            Month(vartoday),
            Day(vartoday)
        )
    )
)

 

12 REPLIES 12
RandyHayes
Super User
Super User

@C_Baugher 

So my next question would be, why are you using a collection for this?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Honestly, I thought referencing a local collection would be faster than going out to that SP list for each translation. Just pull the table into a local collection on load, and then reference that throughout the app to translate any labels as needed. Would that be a false assumption?

RandyHayes
Super User
Super User

@C_Baugher 

It actually will slow down your app.  You are trying to pull ALL of the data from the session table (in the cloud) that then has to pull all of the data from the actual datasource.  So, you end up with a session table with all the data. A datasource with all the data and then a collection with all the data.  

There are times for that type of thing (pulling all records), but the assumption it is faster is wrong.  When you would do that is if you have to have offline capability or if there is some non-delegable criteria that you must perform in the app and there is no way around the delegation and you have more than 2000 records.  Beyond that, it just slows down the app.

As for all the variables, they just clutter the app and make it hard to maintain.

 

My suggestion is the following formula on the OnStart:

With({_usr: User(),
      _lang: First(Split(Language(), "-")).Result},

   Set(AppInfo,
       {
          employeemail: Lower(_usr.Email)
          userlang: Language(),
          userlangshort: _lang
          userlanguagefinal: Coalesce(LookUp(TranslationTerms, Title=_lang, Title), "en")
          existingid:  Filter('FLHA Responses V2', Lower('Created By'.Email) = Lower(_usr.Email)&& IsToday('Submission Date'))
       }
   )
)   

This will give your app one variable called AppInfo that has a record of the information you want.

So, AppInfo.userlanguagefinal, for example, would be the result of the lookup for the user language, or "en" if not found.

AppInfo.existingid would contain a table of records matching your email and date criteria.

(NOTE on that part...you are doing a Lower on the user email, but not on the createdby email...you would really need to compare lower to lower.  I know you did that for delegation, but if the list email address is not lowered then you very well might be missing data from the filter.  If your FLHA Responses V2 is or is expected to be more than 2000 records, then some alternatives should be applied.)

 

Anyway, the above is just a suggestion on simplifying the formulas and making your app easier to maintain.  Take or leave, but it does help.

 

Beyond that concept, I would skip the duplicate collections and just do your lookups and filters direct.  

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,992)