cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
akg1421
Helper III
Helper III

Error when Filtering data source before Creating a Collection

Using mydatasource to create mycollection1 before filtering mydatasource to return only specific rows

ClearCollect(mycollection1,Blank());
ForAll(mydatasource As mydatasource,
	Filter(mydatasource,mydatasource.UserId="Jonathan"),
    Collect(mycollection1,
        {
            FullNameOriginator: LookUp(mycollection2, ID = mydatasource.'User (Originator)','Person name'),
            Status:mydatasource.Status,
            'User (Originator)':mydatasource.'User (Originator)',
            Subject:mydatasource.Subject,
            'Work item instructions':mydatasource.'Work item instructions',
            WorkflowWorkItemClaimed:mydatasource.WorkflowWorkItemClaimed,
            'User (UserId)':mydatasource.'User (UserId)',
            'Due date time':mydatasource.'Due date time'
        }
    )
);

I want to create collection based only on filtered rows returned from my datasource. In above query I am trying to filter but it returns error.

 

Is the syntax correct?

1 ACCEPTED SOLUTION

Accepted Solutions

@akg1421 

 

The second one is closer, but the second one is incorrect as well. As is said in the error message, there are too many arguments to ForAll. In your case, it means that the Filter itself has to be used as the iterable Table in the ForAll. In your second formula, the part where you have 

 

mydatasource As mydatasourceRecord,

 

has to instead be

 

Filter(mydatasource As mdsPreFilteredRecord,mdsPreFilteredRecord.UserId="Jonathan") As mydatasourceRecord

 

 

So like this:

 

ForAll
(
     Filter(mydatasource As mdsPreFilteredRecord,mdsPreFilteredRecord.UserId="Jonathan") As mydatasourceRecord
     ,Collect
     (
        mycollection1
        ,{
             FullNameOriginator: LookUp(mycollection2, ID = mydatasourceRecord.'User (Originator)','Person name')
            ,Status:mydatasourceRecord.Status
            ,'User (Originator)':mydatasourceRecord.'User (Originator)'
            ,Subject:mydatasourceRecord.Subject
            ,'Work item instructions':mydatasourceRecord.'Work item instructions'
            ,WorkflowWorkItemClaimed:mydatasourceRecord.WorkflowWorkItemClaimed
            ,'User (UserId)':mydatasourceRecord.'User (UserId)'
            ,'Due date time':mydatasourceRecord.'Due date time'
        }
     )
);

 

 

Check if it helps @akg1421 

View solution in original post

11 REPLIES 11

@akg1421 


@akg1421 wrote:

 

//
ForAll(mydatasource As mydatasource,....

 


You have assigned your record scope mydatasource to be identical to the data source scope mydatasource - you gave them the exact same name! I do not recommend it.

 

I don't recommend to use As with the identical name as the data source

 

Do it this way.

 

I don't know if it will fix it, but it could be problematic to make the As name identical, so it may be better not to:

 

 

ClearCollect(mycollection1,Blank());
ForAll(mydatasource As mydatasourceRecord,
	Filter(mydatasource,mydatasourceRecord.UserId="Jonathan"),
    Collect(mycollection1,
        {
            FullNameOriginator: LookUp(mycollection2, ID = mydatasourceRecord.'User (Originator)','Person name'),
            Status:mydatasourceRecord.Status,
            'User (Originator)':mydatasourceRecord.'User (Originator)',
            Subject:mydatasourceRecord.Subject,
            'Work item instructions':mydatasourceRecord.'Work item instructions',
            WorkflowWorkItemClaimed:mydatasourceRecord.WorkflowWorkItemClaimed,
            'User (UserId)':mydatasourceRecord.'User (UserId)',
            'Due date time':mydatasourceRecord.'Due date time'
        }
    )
);

 

 

See if this happened to help resolve it. 

akg1421
Helper III
Helper III

@poweractivate 

Which of the following is correct:

First:

ForAll(mydatasource;
Filter(mydatasource,ThisRecord.'User (UserId)' = "Jonathan"),
    Collect(mycollection1,
        {
            FullNameOriginator: LookUp(mycollection2, ID = mydatasource.'User (Originator)','Person name'),
            Status:mydatasource.Status,
            'User (Originator)':mydatasource.'User (Originator)',
            Subject:mydatasource.Subject,
            'Work item instructions':mydatasource.'Work item instructions',
            WorkflowWorkItemClaimed:mydatasource.WorkflowWorkItemClaimed,
            'User (UserId)':mydatasource.'User (UserId)',
            'Due date time':mydatasource.'Due date time'
        }
    )
);

gives error "Incompatible types of comparison. These types can't be compared: Text, Table." at:

LookUp(mycollection2, ID = mydatasource.'User (Originator)','Person name')

 

Second:

ForAll(mydatasource As mydatasourceRecord,
	Filter(mydatasource,mydatasourceRecord.UserId="Jonathan"),
    Collect(mycollection1,
        {
            FullNameOriginator: LookUp(mycollection2, ID = mydatasourceRecord.'User (Originator)','Person name'),
            Status:mydatasourceRecord.Status,
            'User (Originator)':mydatasourceRecord.'User (Originator)',
            Subject:mydatasourceRecord.Subject,
            'Work item instructions':mydatasourceRecord.'Work item instructions',
            WorkflowWorkItemClaimed:mydatasourceRecord.WorkflowWorkItemClaimed,
            'User (UserId)':mydatasourceRecord.'User (UserId)',
            'Due date time':mydatasourceRecord.'Due date time'
        }
    )
);

gives error "Invalid number of arguments: received 3, expected 2."

@akg1421 

 

The second one is closer, but the second one is incorrect as well. As is said in the error message, there are too many arguments to ForAll. In your case, it means that the Filter itself has to be used as the iterable Table in the ForAll. In your second formula, the part where you have 

 

mydatasource As mydatasourceRecord,

 

has to instead be

 

Filter(mydatasource As mdsPreFilteredRecord,mdsPreFilteredRecord.UserId="Jonathan") As mydatasourceRecord

 

 

So like this:

 

ForAll
(
     Filter(mydatasource As mdsPreFilteredRecord,mdsPreFilteredRecord.UserId="Jonathan") As mydatasourceRecord
     ,Collect
     (
        mycollection1
        ,{
             FullNameOriginator: LookUp(mycollection2, ID = mydatasourceRecord.'User (Originator)','Person name')
            ,Status:mydatasourceRecord.Status
            ,'User (Originator)':mydatasourceRecord.'User (Originator)'
            ,Subject:mydatasourceRecord.Subject
            ,'Work item instructions':mydatasourceRecord.'Work item instructions'
            ,WorkflowWorkItemClaimed:mydatasourceRecord.WorkflowWorkItemClaimed
            ,'User (UserId)':mydatasourceRecord.'User (UserId)'
            ,'Due date time':mydatasourceRecord.'Due date time'
        }
     )
);

 

 

Check if it helps @akg1421 

@poweractivate 

It's working fine. Collection is created as per requirement. However, it does not seem to be Filtering data for UserId="Jonathan"

@akg1421 

 

Maybe you want the Collection to be iterated on all items but for the final result to be Filtered - if so, then maybe you want it like this?

Filter
(
	ForAll
	(
		 mydatasource As mydatasourceRecord
		 ,Collect
		 (
			mycollection1
			,{
				 FullNameOriginator: LookUp(mycollection2, ID = mydatasourceRecord.'User (Originator)','Person name')
				,Status:mydatasourceRecord.Status
				,'User (Originator)':mydatasourceRecord.'User (Originator)'
				,Subject:mydatasourceRecord.Subject
				,'Work item instructions':mydatasourceRecord.'Work item instructions'
				,WorkflowWorkItemClaimed:mydatasourceRecord.WorkflowWorkItemClaimed
				,'User (UserId)':mydatasourceRecord.'User (UserId)'
				,'Due date time':mydatasourceRecord.'Due date time'
			}
		 )
	) As processedRecord
	,processedRecord.UserId="Jonathan"
)

 

Does the above work better?

 

@poweractivate Nope, your previous reply resolved the issue. 

Moreover, please guide how can I have the data fully loaded in collection before the user starts navigating through screens. Because the datasource is a "dynamics 365" entity and it takes usually 15 to 20 seconds before data is fully loaded and showing in Gallery.

 

I have tried App.OnStart() - Didn't work! I then tried LandingScreen.OnVisible() that also didn't work. What would be the right way to STOP user from navigating before the data is completely iterated and stored in collection.

@akg1421 

 

On the first screen of your app, have a big Label that says PLEASE WAIT.

Have a Timer Control on that same first screen where the big PLEASE WAIT label is, that is repeating each second. Make the Duration be 1000 to do this

Make the AutoStart property to be true

Make the Repeat property to be true

OnTimerEnd of the Timer control, use CountRows to check how many Records are in the Collection you are trying to load into.

 

If it is greater than some number of your choice, use Navigate(MainAppScreen) 

So for OnTimerEnd of the Timer control something like this:

 

If(CountRows(myCollection)>50,Navigate(MainAppScreen))

 

 Otherwise the Timer will auto repeat and check it again in another second.

 

See if something like the above could help as starting point @akg1421 

@poweractivate 

 

It just loops around with timer resetting. CountRows is dynamic, it may never be greater than the number of choice. It's values range from 0 to 50

 

If(CountRows(myCollection)>50,Navigate(MainAppScreen))

 

 

Any solution to this?

@akg1421 

 

Instead of 50 just use 0 - or use a smaller number like 5 or 10 does it work better that way?

Try just 0 for now, it sounds like you don't have so many records right now - so just use 0.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,148)