I want to create many rules ...
Rule 1: If ThisItem.FirstName="Mickey","Good","Bad")
Rule 2: If ThisItem.FirstName="Minnie","Good","Bad")
Rule 3: If ThisItem.FirstName="Ultron","Bad","Good")
In the above case these are very simple...
I need to reuse this code on multiple screens.
I was trying to think of a way to store this code and reuse it multiple times.
I will have about 20 rules and they have numerous conditions.
Each rule will have a version for being on a gallery and one for running the rule without the ThisItem.FirstName.
For ease, I thought I could create a collection with
Collect(Rules,
{ Rule: 1, Code: If(ThisItem.FirstName="Mickey","Good","Bad")},
{ Rule: 2, Code: If(ThisItem.FirstName="Minnie","Good","Bad")},
.....
)
But...
It would need to be done like this...
Collect(Rules,
{ Rule: 1, Code: "If(ThisItem.FirstName='Mickey','Good','Bad')"},
{ Rule: 2, Code: "If(ThisItem.FirstName='Minnie','Good','Bad')"}
)
Now, the code is Text
and then in my appropriate place...
I could add a label ... with a text property of ...
If(LookUp(Rules,Rule=1,CodeGallery),"OK","Fail")
But of course it doesn't work...
It can read the value but it's treating it I suppose as literal text.
Is there a way around it "such as a convert function from text to code 😉
Solved! Go to Solution.
There is no way to translate from literal code stored in the system into actual code. This is the same security risk as a traditional SQL insertion attack. So there is no provision for doing it this way. You can see if there is a way to encapsulate the rules as a component and then use input and output parameters to apply the code rules for re-use. But the rules will then need to be entered into the component as static code. It just would allow for re-use wherever you add the component.
Yeah, that makes sense. Then at that point I might as well just write the code ... good to know. thank you.
There is no way to translate from literal code stored in the system into actual code. This is the same security risk as a traditional SQL insertion attack. So there is no provision for doing it this way. You can see if there is a way to encapsulate the rules as a component and then use input and output parameters to apply the code rules for re-use. But the rules will then need to be entered into the component as static code. It just would allow for re-use wherever you add the component.
Yeah, that makes sense. Then at that point I might as well just write the code ... good to know. thank you.
The one advantage to the component approach would be the ability to use it in multiple places. Otherwise, yes you might as well cut and paste the code as needed.
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
User | Count |
---|---|
184 | |
51 | |
47 | |
34 | |
32 |
User | Count |
---|---|
258 | |
88 | |
78 | |
68 | |
67 |