cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Advocate V
Advocate V

Can I create a collection based on a global variable?

I have multiple, identical SharePoint lists and I'd like to load a particular list on all screens based on a global variable called varProject.  I'd like to be able to set all forms and galleries to have a data source of colClaimsList, and then switch out the records they display based on a global variable selection set with a button click on the home page of the app.

 

With the global variable is set, I hoped to create a collection (using ClearCollect) based on the varProject value.

The variable is getting set correctly, but I can't seem to get the collection created. I'm doing stuff like this:

 

If(
    varProject = "Project1",
    ClearCollect(
        colClaimsList,
        'Claims-Project1'
    );
    If(
        varProject = "Project2",
        ClearCollect(
            colClaimsList,
            'Claims-Project2'
        )
    )
);
Navigate(SELECT)

 


Is this not possible? Powerapps seems perfectly happy with the syntax but the collection is not being created/populated. It's always empty. Thanks in advance for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User III
Super User III

@RachelRig 

You will only be able to do this successfully if the two sources are the same.  Otherwise you will start to introduce issues into your app.

Your formula can be set to the following:

ClearCollect(
   colClaimsList,
   Switch(varProject, "Project1", 'Claims-Project1', "Project2", 'Claims-Project2')
)

Again note, that these should be pretty much identical.

 

I hope this is helpful for you.

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too!

View solution in original post

2 REPLIES 2
Super User III
Super User III

@RachelRig 

You will only be able to do this successfully if the two sources are the same.  Otherwise you will start to introduce issues into your app.

Your formula can be set to the following:

ClearCollect(
   colClaimsList,
   Switch(varProject, "Project1", 'Claims-Project1', "Project2", 'Claims-Project2')
)

Again note, that these should be pretty much identical.

 

I hope this is helpful for you.

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too!

View solution in original post

@RandyHayes Thanks so much! I was experimenting with Switch functions but I didn't have it quite right. This is working for me now. 

ClearCollect(
    colClaimsList,
    Switch(
        varProject,
        "Project1",
        "Claims-Project1',
        "Project2",
        'Claims-Project2',
        "Project3",
        'Claims-Project3'
    )
);

Helpful resources

Announcements
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (7,225)