cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
bkeano
Level: Powered On

Question on ClearCollect, Delegation and SQL

Hi
I have an APP that is designed to work offline, as the users maybe on sites with bad or no connectivity at times
The backend Database is SQL On Premise, as we later use the data from the APP data for some other purposes.

The data captures work done by an operator and in the form it also includes images ( Signatures X 2 and a picture of a printout from a machine). The images are not massive, usualy around 300KB for all 3.

 

To keep performace decent we only retrieve 40 records and only show the operator any records that he has within that 40 ( so using a filter on his login name, the administrator can see more records)

My question is , will delegation and performace become an issue later?

Specifically, if I put a filter on the ClearCollect command does it just load the last 40 (LastN=40), or does it load up to 500 (delegation limit) and then filter out 40? Below the formula I'm using when the user logs in. 
If it's loading more than my 40 and then filtering, my performace will be poor, as each record could be 500KB....!

Any clarifications much appreciated

ConnectFornula.JPG

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
bkeano
Level: Powered On

Re: Question on ClearCollect, Delegation and SQL

Hi Jahall
Problem sorted! It was the global variable that was causing the issue.
Not sure if this is a bug or not, as the global variable does correctly filter, but when it' been used and passed in delegation to SQL server it does not work, or it does not work in delegation inside the Filter command

Explanation:
I was setting a global variable further up the 'OnSelect' as below

Set(LoginUser,Combo_UserAccount.Selected.Fullname);

Then using this variable further down the same 'OnSelect' statement, so using 'Driver=LoginUser'.
But instead of using 'Driver=LoginUser', I substituted it with the source field itself 'Combo_UserAccount.Selected.Fullname', so my new statement, including working SORT!, is below

If(Connection.Connected,                    
        Refresh('[dbo].[PASPRAYING]');
        ClearCollect(PASPRAYINGLocalCollect, 
                      Filter(Sort('[dbo].[PASPRAYING]',ordID,SortOrder.Descending),Driver=Combo_UserAccount.Selected.Fullname)
                      );
        SaveData(PASPRAYINGLocalCollect, "PASPRAYINGLocalCache")
    )


My delegation limit is set as '5', and it correctly now delegates and pulls back the most recent records from the table! Happy days!  Means I don't have to write a load of SQL views etc
Thanks for the point in right direction!

 

6 REPLIES 6

Re: Question on ClearCollect, Delegation and SQL

I haven't any experience in offline apps, but for delegation there is a golden rule. If you create a formula which will have delegation issues you will see a blue underline under the part that has deletagion issues and also a exclamation icon in the app. If you dont see any of it, delegation works.

bkeano
Level: Powered On

Re: Question on ClearCollect, Delegation and SQL

Thanks for reply Magnus

Though this is exactly my problem, I had an issue in another APP ( no offline ability), there were no delegation warnings, but the refresh seemed to just grab the last 500 records, then applied function LAST (in this case), to what it retrieved. I increased the delegation limit in that APP and problem solved, so defo issue on delegation. So this is why some clarification would be help

 

It especially worries me for the offline APP, firstly as the record set grows I don't want it to grab 500 records, just the last 40, and secondly I want the actual last 40, not 40 from the delegation limit of 500...Smiley Frustrated

 

jhall
Level 8

Re: Question on ClearCollect, Delegation and SQL

You're correct to be concerned, but you can do some basic Filters to delegate.

First, you might want to check out the reference here, but I also think there's a pretty good real-world discussion here.

Essentially, if you do a ClearCollect(myVariable,Filter(spList,{your criteria here})), then it will all happen upstream and you will only transfer what matches if you use some basic comparisons.  Just don't get crazy w/ sorts and whatnot on your ClearCollect.

 

For example:  ClearCollect(myUserList,Filter(spUserList,Department="Marketing")
bkeano
Level: Powered On

Re: Question on ClearCollect, Delegation and SQL

Thanks for reply JHall

I reduced my delegation APP limit to '5' , as suggested by some of the posts to really test the delegation.

Unfortunately still not getting the result......

 

Whats happening is that the delgation limit is the number of records that goes into the collection from the source DB Smiley Sad

And even if I use SORT ( get no delegation warnings) it is still the oldest 5 records that go inot the collection Smiley SadSmiley Sad

If(Connection.Connected,                    
        Refresh('[dbo].[PASPRAYING]');
        ClearCollect(PASPRAYINGLocalCollect, 
            If(Administrator=false,
                      Filter(Sort('[dbo].[PASPRAYING]',ordID),Driver=LoginUser),
                      '[dbo].[PASPRAYING]'
                )
                      );
        SaveData(PASPRAYINGLocalCollect, "PASPRAYINGLocalCache")
    )

Am I missing something here?
The documents say delegation does not work with Collect, I can understand that, but my belief is that it should populate the collection based on any filters and sorts placed on the source SQLDB?

So if I filter the source DB and source it, those functions should be delegated, then the data retrievd to populate the collection
If not, it's a big restriction for offline APPs, and the only solution I can see is to change my SQL DB model, so that it becomes a dynamic (archived periodically or something like that) table keeping everything small?

jhall
Level 8

Re: Question on ClearCollect, Delegation and SQL

You're correct in your thinking.  Collect/ClearCollect aren't delegable, so you use Filters on the inputs to them which ARE delegable.  However, I don't believe SORT is delegable, so it's getting the first X records from the source, then sorting, which isn't helping you.  At least I think that is the case.

I would still look at the exact value of this portion of your query

Driver=LoginUser

The easiest thing to miss here is case, so you might just review the data held in the table/column and the variable.

Now, if you're getting into some advanced queries and/or tying tables together or running into some tough limits, you can always have someone create a callable view on your data source.  If you did the Sort/Filter there on universal values (e.g. Nothing older than X), then it would simplify queries against the source.  It looks like you might be calling these from SQL so that might be an possible option if you're getting trapped per performance.

bkeano
Level: Powered On

Re: Question on ClearCollect, Delegation and SQL

Hi Jahall
Problem sorted! It was the global variable that was causing the issue.
Not sure if this is a bug or not, as the global variable does correctly filter, but when it' been used and passed in delegation to SQL server it does not work, or it does not work in delegation inside the Filter command

Explanation:
I was setting a global variable further up the 'OnSelect' as below

Set(LoginUser,Combo_UserAccount.Selected.Fullname);

Then using this variable further down the same 'OnSelect' statement, so using 'Driver=LoginUser'.
But instead of using 'Driver=LoginUser', I substituted it with the source field itself 'Combo_UserAccount.Selected.Fullname', so my new statement, including working SORT!, is below

If(Connection.Connected,                    
        Refresh('[dbo].[PASPRAYING]');
        ClearCollect(PASPRAYINGLocalCollect, 
                      Filter(Sort('[dbo].[PASPRAYING]',ordID,SortOrder.Descending),Driver=Combo_UserAccount.Selected.Fullname)
                      );
        SaveData(PASPRAYINGLocalCollect, "PASPRAYINGLocalCache")
    )


My delegation limit is set as '5', and it correctly now delegates and pulls back the most recent records from the table! Happy days!  Means I don't have to write a load of SQL views etc
Thanks for the point in right direction!

 

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 200 members 4,785 guests
Please welcome our newest community members: