cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BenMunk
Helper I
Helper I

Creating a Stylesheet using a Record Variable

Is there a way to create a RECORD type global variable from a Sharepoint list?  eg something like FirstN(datasource,1) ?

 

Here's the background...

 

I'm trying to create a pseudo stylesheet.  I have an approach that works. But I need some help to make it one step better.

 

At app.OnStart I'm setting a global variable like so

 

Set(Styles,{
            colorPrimaryDarkBlue: RGBA(32,70,102,1),
            colorPrimaryLightBlue: RGBA(61, 107, 153, 1),
            FontColor: RGBA(50,50,50,1),
            ...
 
This creates a RECORD type variable.
 
Then for each Control Property I can simply refer to the value using dot notation  eg for Color I specify a reference like Styles.FontColor
 
Snag_7696de1.png
 
However, I would really like to pull the "stylesheet" from a sharepoint list. 
 
Every way I have tried LookUp, Filter, FirstN  - brings the data in to the global variable as a TABLE type variable, which cannot be referenced with the elegant dot notation (like Styles.FontColor).
 
Any ideas?
 
 

 

1 ACCEPTED SOLUTION

Accepted Solutions

You don't need to specifically name the column in your Record variable.   The example I gave you is a working example from one of my apps.  The properties of the variable are not the same as the column names.  

 

Here is an example of what I use in all my apps. 

 

 

Set(Style,
 {
  ButtonFill: RGBA(249, 230, 173, 1),	
  ChevronBackground: RGBA(249, 230, 173, 1),
  ChevronFill: RGBA(78, 128, 137, 1),
  ChevronHoverBackground: ColorFade(RGBA(78, 128, 137, 1), -20%),
  ChevronHoverFill: RGBA(78, 128, 137, 1),
  ControlBorderColor: RGBA(78, 128, 137, 1),
  ControlBorderThickness: 2,
  FocusedBorderThickness: 4,
  HoverFill: RGBA(244, 233, 198, 1),
  IconBackground: RGBA(249, 230, 173, 1),
  IconFill: RGBA(249, 230, 173, 1),
  IconSize: 40,
  MenuComponentsFill: RGBA(139, 170, 172, 1),
  MenuFontColor: RGBA(36, 85, 86, 1),
  PressedFill: RGBA(68, 90, 106, 1),
  SelectionColor: White,
  SelectionFill: RGBA(250, 237, 197, 1)
 }
);

 

 

Rather than manually setting it in the app like this, you would do it this way.

 

 

Set(Style,
  {
    colorPrimaryDarkBlue: LookUp(SharePointList, Property = colorPrimaryDarkBlue).Value,
    colorPrimaryLightBlue: LookUp(SharePointList, Property = colorPrimaryLightBlue).Value,
    colorSecondaryGold: LookUp(SharePointList, Property = colorSecondaryGold).Value,
    colorSecondaryGrey1: LookUp(SharePointList, Property = colorSecondaryGrey1).Value
  }
)

 

 

If you used a label to see the values of your Style variable it would look like this and give you the .notation you are looking for.

 

StyleVariable2.jpg        StyleVariable.jpg

 

 



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

View solution in original post

5 REPLIES 5
JR-BejeweledOne
Super User
Super User

You can do this.  Here is an example from a working app:

 

 

Set(varLicenseCost,
   {
     PAUserCost: LookUp(LicenseData, Application = "Power Apps" And Title = "Per User").Cost,
     PAAppCost: LookUp(LicenseData, Application = "Power Apps" And Title = "Per App").Cost,
     PAAutomateCost: LookUp(LicenseData, Application = "Power Automate" And Title = "Per User").Cost
   }
     );

 



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

Thanks for your reply.  I'm still a bit stuck though. Another way to explain what I'm trying to do...

 

Take this Sharepoint list

Property                             Value
colorPrimaryDarkBlueRGBA(32,70,102,1)
colorPrimaryLightBlue       RGBA(61, 107, 153, 1)
colorSecondaryGold         RGBA(255,204,0,1)
colorSecondaryGrey1RGBA(200,209,216,1)
etc etc 

 

And turn it in to a Record variable (but without explicitly name each column in the function)

colorPrimaryDarkBluecolorPrimaryLightBluecolorSecondaryGoldcolorSecondaryGrey1 
RGBA(32,70,102,1)RGBA(61, 107, 153, 1)RGBA(255,204,0,1)RGBA(200,209,216,1) 

 

I guess what I'm trying to do is TRANSPOSE, then LOOKUP.

 

Seems TRANSPOSE is not possible in PowerApps without hardcoding the columns.

 

I have just found and upvoted here: 

https://powerusers.microsoft.com/t5/Power-Apps-Ideas/Provide-a-function-to-transpose-convert-rows-to...

 

 

 

You don't need to specifically name the column in your Record variable.   The example I gave you is a working example from one of my apps.  The properties of the variable are not the same as the column names.  

 

Here is an example of what I use in all my apps. 

 

 

Set(Style,
 {
  ButtonFill: RGBA(249, 230, 173, 1),	
  ChevronBackground: RGBA(249, 230, 173, 1),
  ChevronFill: RGBA(78, 128, 137, 1),
  ChevronHoverBackground: ColorFade(RGBA(78, 128, 137, 1), -20%),
  ChevronHoverFill: RGBA(78, 128, 137, 1),
  ControlBorderColor: RGBA(78, 128, 137, 1),
  ControlBorderThickness: 2,
  FocusedBorderThickness: 4,
  HoverFill: RGBA(244, 233, 198, 1),
  IconBackground: RGBA(249, 230, 173, 1),
  IconFill: RGBA(249, 230, 173, 1),
  IconSize: 40,
  MenuComponentsFill: RGBA(139, 170, 172, 1),
  MenuFontColor: RGBA(36, 85, 86, 1),
  PressedFill: RGBA(68, 90, 106, 1),
  SelectionColor: White,
  SelectionFill: RGBA(250, 237, 197, 1)
 }
);

 

 

Rather than manually setting it in the app like this, you would do it this way.

 

 

Set(Style,
  {
    colorPrimaryDarkBlue: LookUp(SharePointList, Property = colorPrimaryDarkBlue).Value,
    colorPrimaryLightBlue: LookUp(SharePointList, Property = colorPrimaryLightBlue).Value,
    colorSecondaryGold: LookUp(SharePointList, Property = colorSecondaryGold).Value,
    colorSecondaryGrey1: LookUp(SharePointList, Property = colorSecondaryGrey1).Value
  }
)

 

 

If you used a label to see the values of your Style variable it would look like this and give you the .notation you are looking for.

 

StyleVariable2.jpg        StyleVariable.jpg

 

 



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

View solution in original post

JR-BejeweledOne
Super User
Super User

You could also take a look at this:

 

https://powerusers.microsoft.com/t5/Building-Power-Apps/Transposing-and-Merging-Collections/td-p/959...



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

Thanks very much for your help, and for the link.  

 

I guess I was really hoping to have a method that can be used across multiple apps, so I could add another style property to the list, and it automatically becomes available to all apps (I have 40 apps for one client).

 

The 2nd approach you suggested gets the closest.  This won't handle handle automatic additions, but it will handle automatic updates of existing styles.  So this is quite handy.  And might be the best solution for now.

 

Set(Style,
  {
    colorPrimaryDarkBlue: LookUp(SharePointList, Property = colorPrimaryDarkBlue).Value,
    colorPrimaryLightBlue: LookUp(SharePointList, Property = colorPrimaryLightBlue).Value,
    colorSecondaryGold: LookUp(SharePointList, Property = colorSecondaryGold).Value,
    colorSecondaryGrey1: LookUp(SharePointList, Property = colorSecondaryGrey1).Value
  }
)

 

With some further research, I think this might be the only way to get exactly what I'm after: 

https://powerusers.microsoft.com/t5/Building-Power-Apps/Transpose-Data-Collection/td-p/1274129

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

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