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

Use different cds based on certain condition (Storing cds entity in variable)

Hi,

Is it possible to use different cds entity based on certain condition?
Like(this gives error):
If(user.condition1 = true, Set(cdsname, CDS1), Set(cdsname, CDS2));
Patch(
    cdsname,
    Defaults(cdsname),
    {
        Name: "Test",
        ImageContent: LargeImage.Image
    }
);

Here is why I want to do this:
I am developing an app that stores large image data to cds (image resolution is important).
When number of records is small, app works fine, but when number of records exceeds about 300, operations like patch, filter, etc become very slow, sometimes resulting in app's crash.

I thought daily backup and removing old records might be good, but it turned out daily number of records might already exceed 300. So next idea was using different cds based on certain condition (f.ex. one user one cds entity). But in this case I would need to insert if statement every time I want to use that cds.
So I thought storing cds entity into a variable might be the solution, but the code above gives error.

Any help is appreciated. Thank you.



1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Use different cds based on certain condition

You can do this: 

If(user.condition1 = true, 
Patch(
    CDS1,
    Defaults(CDS1),
    {
        Name: "Test",
        ImageContent: LargeImage.Image
    }
),
Patch(
    CDS2,
    Defaults(CDS2),
    {
        Name: "Test",
        ImageContent: LargeImage.Image
    }
))

Let me know if this helps. 

 

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution.

 

Thanks!
Hardit Bhatia
https://thepoweraddict.com

View solution in original post

6 REPLIES 6
Highlighted
Super User
Super User

Re: Use different cds based on certain condition

Are you talking about using different entities or different CDS instances?

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution.

Thanks!
Hardit Bhatia
The Power Addict
https://thepoweraddict.com
Highlighted
New Member

Re: Use different cds based on certain condition

Hello, I am referring to cds entity.

Highlighted
Super User
Super User

Re: Use different cds based on certain condition

You can do this: 

If(user.condition1 = true, 
Patch(
    CDS1,
    Defaults(CDS1),
    {
        Name: "Test",
        ImageContent: LargeImage.Image
    }
),
Patch(
    CDS2,
    Defaults(CDS2),
    {
        Name: "Test",
        ImageContent: LargeImage.Image
    }
))

Let me know if this helps. 

 

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution.

 

Thanks!
Hardit Bhatia
https://thepoweraddict.com

View solution in original post

Highlighted
New Member

Re: Use different cds based on certain condition

Hi, I know I can do this, but in this case I would need to insert if statement every time I want to use that cds, and I am using that cds in over 20-30 places. That might bring a very long redundant code.

In normal programming language, setting datasource in a variable would't be a big problem.

Highlighted
Super User
Super User

Re: Use different cds based on certain condition

With Power Apps, you cannot set an entity name as text and then use it in a function like Patch.

This might be your only option.

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution.

Thanks!
Hardit Bhatia
https://thepoweraddict.com
Highlighted
Community Support
Community Support

Re: Use different cds based on certain condition

Hi @arisima1 ,

 

In PowerApps, the source parameter of Patch function must be a Data source or Collection, the variable is not supported.

If you want to do some modification on the data source, you have to hardcode the data source name in Patch function.

So I think @PowerAddict 's workaround is the most suitable for your case for the time being.

If you want that new feature, please submit an idea to PowerApps Idea Forum. https://powerusers.microsoft.com/t5/Power-Apps-Ideas/idb-p/PowerAppsIdeas . If there are a lot of votes, the team will give priority to adding this new feature.

 

Sik

 

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (8,377)