cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sasrsc1966
Resolver I
Resolver I

Variables containing code? for my rules...

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 TextRegion Capture.jpg
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 😉


2 ACCEPTED SOLUTIONS

Accepted Solutions
Pstork1
Dual Super User
Dual Super User

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Yeah, that makes sense. Then at that point I might as well just write the code ... good to know. thank you.

View solution in original post

3 REPLIES 3
Pstork1
Dual Super User
Dual Super User

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (1,800)