cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BarnBrat
New Member

How to Create Collection Based on If statement

I have a gallery and several filters, searches and all is working fine, however I want to put the records into a collection and I cannot for the life of me figure out how to put the results of the IF statement into a collection. Everything I try gives me an error. If I try to wrap the Filter statement in a Clear Collect, I get this error: 

BarnBrat_0-1635864147224.png

 

 

Basically I want to create a collection and be able to assign whatever the results of this IF statement are to the collection so that I can reference the collection elsewhere. Any ideas as to where I am going wrong?

 

Here is the If statement that is on the galARSTRecords.This:

If(ddSearchBy.Selected.Value = "Check Number" And ddFilter.Selected.Result = "All",
Filter('ARST Check Manager',StartsWith('Check Number',txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Student ID" And ddFilter.Selected.Result = "All",
Filter('ARST Check Manager',StartsWith(Vendor,txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Last Name" And ddFilter.Selected.Result = "All",
Filter('ARST Check Manager',StartsWith('Last Name',txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Check Number" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Status",
Sort(Filter('ARST Check Manager',Action.Value = ddFilter.Selected.Result And StartsWith('Check Number',txtSearch.Text)),'Action Date',Descending),

 

ddSearchBy.Selected.Value = "Student ID" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Status",
Filter('ARST Check Manager',Action.Value = ddFilter.Selected.Result And StartsWith(Vendor,txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Last Name" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Status",
Filter('ARST Check Manager',Action.Value = ddFilter.Selected.Result And StartsWith('Last Name',txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Check Number" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Term",
Filter('ARST Check Manager',Term = ddFilter.Selected.Result And StartsWith('Check Number',txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Student ID" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Term",
Filter('ARST Check Manager',Term = ddFilter.Selected.Result And StartsWith(Vendor,txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Last Name" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Term",
Filter('ARST Check Manager',Term = ddFilter.Selected.Result And StartsWith('Last Name',txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Check Number" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Type",
Filter('ARST Check Manager','AR Type'= ddFilter.Selected.Result And StartsWith('Check Number',txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Student ID" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Type",
Filter('ARST Check Manager','AR Type' = ddFilter.Selected.Result And StartsWith(Vendor,txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Last Name" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Type",
Filter('ARST Check Manager','AR Type' = ddFilter.Selected.Result And StartsWith('Last Name',txtSearch.Text)),

 

'ARST Check Manager')

1 ACCEPTED SOLUTION

Accepted Solutions
v-xiaochen-msft
Community Support
Community Support

Hi @BarnBrat ,

 

The error message is because you used the behavior function on the wrong control property.

ClearCollect() funcion is a behavior function. It can only be triggered after a event is executed.

For example: When you click on a button and trigger an event, the clearcollect function will be executed.

So you could use ClearCollect() function on the Onselect property of button control.

In addition, there are many such properties, e.g. Onchange , OnVisible,... 

 

Best Regards,

Wearsky

View solution in original post

4 REPLIES 4
gabibalaban
Super User
Super User

@BarnBrat ,

Actually if you use the formula in Items property of the Gallery, the results of the formula can be use as a collection with  galARSTRecords.AllItems.

Hope it helps !

I hear what you are saying, and that is what I want to do, but it's the how that I cannot figure out...

I think I am catching on. After I figure out how to initially load all of the records into the collection, I'll post what I've done 🙂

v-xiaochen-msft
Community Support
Community Support

Hi @BarnBrat ,

 

The error message is because you used the behavior function on the wrong control property.

ClearCollect() funcion is a behavior function. It can only be triggered after a event is executed.

For example: When you click on a button and trigger an event, the clearcollect function will be executed.

So you could use ClearCollect() function on the Onselect property of button control.

In addition, there are many such properties, e.g. Onchange , OnVisible,... 

 

Best Regards,

Wearsky

View solution in original post

Helpful resources

Announcements
User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (2,330)