Thursday, April 21, 2022

Copying sharepoint multi user field values from one item to another in powerapps

'Target Field Name':ForAll(varSourceItem.'Source Field Name',{

                    '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",

                    Claims: Claims,

                    Department: Department,

                    DisplayName: DisplayName,

                    Email: Email,

                    JobTitle: JobTitle,

                    Picture: Picture

                })

Tuesday, March 29, 2022

Mass-changing powerapps controls settings

One of the most annoying powerapps restrictions is when you add a form (edit or view), all cards exist independently from each other and there is no way to "theme" them to look the same. 

So if I have an application with lots of forms and I want to have all the labels be a specific font, font size and weight, I have to do it on each label, in each form....uggghh!

The solution I came up with is:
  1. Install VSCode and the powerapps extension in vscode (Power Apps Guide - Code - The new easier way to pack and unpack canvas app source code - Power Apps Guide - Blog)
  2. download your app, and extract it using the extension (see link above for detailed instructions):
    pac canvas unpack --msapp .\myapp.msapp --sources .\myapp\
  3. Decide on a single label that will be your master label, or a variable name that will contain your defaults. we will need the name of that label or the variable for later - lets call it XYZ for now.
  4. open the app folder in vs code, and do a find and replace with the following settings:
In the find box, turn on reg ex and type:
^(\s*DataCardKey.*As label:)

this will find all lines that start with "DataCardKey" and end with "As label:".
By default these are the lines that microsoft powerapps will add to the code when adding a data card. This is the definition of the header (label) of the data card.

In the replace box, type:
$1
                    FontWeight: =XYZ.FontWeight
                    Color: =XYZ.Color

This will add to all instances of the "datacardkey?? as label:" the fontweight and color (in this example) to copy from your "master" label. Alternatively you can create app wide variables for the weight\color or other properties.
You will probably need to fix some problems that the vscode will highlight.

Next, re-pack the app:
pac canvas pack --sources .\ --msapp c:\code\myapp.msapp

Then upload it to a new canvas app (or override the existing one)
Create a canvas app, click "file">"open".

Now if you change the properties you configured on the master label, everything else will flow.