PowerApps Rocks!

Whats your PowerConfig?

Updated code!: 2023-07-18T20:14:12-07:00

The OnStart property in PowerApps is super important to get right. Its the place to communicate critical info about your app to developers (and your future self) as well as setup users for a good experience. So how do you craft a great OnStart config?

I'll break down each piece I put in OnStart, then provide a complete example below.

Start with the important stuff

As shown in the post Wheres the Code!?, the first place to find critical PowerApps code is the App OnStart property. Start off with a copyright notice and a link to the change log. OnStart provides a centralized place for simple documentation that travels with the app. Keep it short and concise. The curious can always reach out directly for more info.

Example:

/*==========================================
Copyright <your-org> 2023
Change log: <link-to-doc-in-Sharepoint>
==========================================/*

Set global variables

I always add the Office365Users Connector to all apps. This free Connector provides the SearchUserV2 method for personalizing the app based on who is logged in.

Example:

Set(varUser,
    Office365Users.SearchUserV2(
        {
            searchTerm: User().Email
        }
    ).value
);

Define some metadata

There are a few simple values to define about the app itself that can be used on subsequent screens. App Name can be used on headers of each screen. Version Number and Environment can be used in footers on each screen to give users info on which app they are testing/using.

Example:

Set(varAppName, "Cool Tool");
Set(varSupportContact,"[email protected]");
Set(varLogo,'uploaded-media');
Set(varEnv,"DEV");
Set(varVersion, "v0.9");

Note: uploaded-media refers to an embedded image added via File/Media.

  • You could reference a url of an image hosted out on the web, but this would require fetching the asset.
  • User would see a blank logo while the call is made
  • Best to embed a logo image so load times are instant

Define a support contact and support email subject/body

I like to provide users a way on every screen to contact dedicated support via email. The HTML below makes a very nice footer to apply to each screen. When clicked, it opens up a pre-filled email direct to support.

Set(varSupportLink,
    "<center>
        Version: " & varEnv & " " & varVersion & "|" & 
        "<a style='color:blue' href=mailto:" & varSupportContact & "?subject=" & 
            EncodeUrl(
                "Support Request: " & 
                varAppName
            ) & 
            "&body=" & 
            EncodeUrl(
                "Hello," & 
                Char(13) & Char(13) & 
                "-Issue:" & 
                Char(13) & Char(13) & 
                "Thank you," & 
                Char(13) & 
                First(varUser).DisplayName
            ) & 
        ">Contact Support </a>" & "|" & 
        "&copy; My Org " & Year(Now()) & 
    "</center>"
)

Define app colors

I tend to keep coloring very simple. I use a 3 color palette of Primary, Secondary and Accent Colors. Setting these in OnStart allows me to call them easily throughout the app.

Example:

Set(varPrimaryColor, ColorValue("#27ad74")),
Set(varSecondaryColor, ColorValue("#00bfff")),
Set(varAccentColor, ColorValue("#f49d02"))

Extras

Define offline behavior

Offline can be challenging to get right. I've also come across scenarios where the PowerApps iOS container app does not always allow your app to be opened when offline. Your mileage may vary, but here is how to setup offline capabilities in theory using OnStart.

// If app is online...

If(
    Connection.Connected,

        // ...create Collections of all required tables...
        // ...could be SQL, Sharepoint, etc. 

        Concurrent(
            Set(varIsSaveDataSupported, true),
            ClearCollect(colCustomers, '[dbo].[Customers]'),
            ClearCollect(colCustomerAddresses, customerSharepointList)
        );

        // ...and sync these fresh tables to the device.

        Concurrent(
            SaveData(colCustomers,"lclCustomers"),
            SaveData(colCustomerAddresses,"lclCustomerAddresses")
        ),

    // If app is offline...

    !Connection.Connected,

        //...create Collections from local cache of all required tables.

        Concurrent(
            LoadData(colCustomers,"lclCustomers"),
            LoadData(colCustomerAddresses,"lclCustomerAddresses")
        )
)

Complete example

/*==========================================
Copyright <your-org> 2023
Change log: <link-to-doc-in-Sharepoint>
==========================================/*

// Set global variables

Concurrent(
    Set(varUser,Office365Users.SearchUserV2({searchTerm: User().Email}).value),
    Set(varAppName, "Cool Tool"),
    Set(varSupportContact,"[email protected]"),
    Set(varLogo,'uploaded-media'),
    Set(varEnv,"DEV"),
    Set(varVersion, "v0.9"),

    // If app is online...

    If(
        Connection.Connected,

            // ...create Collections of all required tables...
            // ...could be SQL, Sharepoint, etc. 

            Concurrent(
                Set(varIsSaveDataSupported, true),
                ClearCollect(colCustomers, '[dbo].[Customers]'),
                ClearCollect(colCustomerAddresses, customerSharepointList)
            );

            // ...and sync these fresh tables to the device.

            Concurrent(
                SaveData(colCustomers,"lclCustomers"),
                SaveData(colCustomerAddresses,"lclCustomerAddresses")
            ),

    // If app is offline...

        !Connection.Connected,

            //...create Collections from local cache of all required tables.

            Concurrent(
                LoadData(colCustomers,"lclCustomers"),
                LoadData(colCustomerAddresses,"lclCustomerAddresses")
            )
    )
);

Set(varSupportLink,
    "<center>
        Version: " & varEnv & " " & varVersion & "|" & 
        "<a style='color:blue' href=mailto:" & varSupportContact & "?subject=" & 
            EncodeUrl(
                "Support Request: " & 
                varAppName
            ) & 
            "&body=" & 
            EncodeUrl(
                "Hello," & 
                Char(13) & Char(13) & 
                "-Issue:" & 
                Char(13) & Char(13) & 
                "Thank you," & 
                Char(13) & 
                First(varUser).DisplayName
            ) & 
        ">Contact Support </a>" & "|" & 
        "&copy; My Org " & Year(Now()) & 
    "</center>"
)

Things to remember

Keep it simple!

Notice, there are some ClearCollect statements, and Office365Users API calls, etc. This is typically not the best practice. The best practice is to only perform API calls and such when the user needs to see the data. Don't make everyone wait while umpteen records are loaded OnStart if only 10% of users actually need that data! You could use the OnVisible properties of each screen instead to make these calls instead.

Use your discrection.

Tags:
powerapps | standards |

Related posts