Best Practices Canvas Apps Expressions

V – Version – How to auto-number app versions?

A person walking on a mat of square numbered blocks
A person walking on a mat of square numbered blocks

Introduction

One challenge with canvas apps is that sometimes users don't have the latest version on their devices. Sure you can add a label for app version and ask app makers to update the number every time they open the studio, make a change, and publish the app. However, all of us forget to do that.

Version autonumbering

Here is a process to automate updates to the version number. Follow these steps:

  1. Create a table in your data source to store version numbers (could be Dataverse, SharePoint or any other data source).
  2. Add a new numeric column to store the version number.
  3. In the OnVisible of the 1st screen or in the OnStart of the app, check if the user is in the studio or not.
  4. You can find this out by checking if IsBlank(Param("tenantId")) is true or not.
  5. Count the number of rows in the table.
  6. If there are no rows, create a new one using the Patch function.
  7. If there is one, increment the version number by one and update that record.
  8. Add a label on the 1st screen to display the version number and the last modified on timestamp.

Here is the code:

Set(
    gblIsAppInStudio,
    IsBlank(Param("tenantId")) && IsBlank(Acceleration.X) && IsBlank(Location.Altitude)
);
If(
    gblIsAppInStudio,
    If(
        CountRows('App Versions') = 0,
        Patch(
            'App Versions',
            Defaults('App Versions'),
            {
                Name: "App Version",
                'Version Number': CountRows('App Versions') + 1
            }
        ),
        Patch(
            'App Versions',
            First('App Versions'),
            {'Version Number': First('App Versions').'Version Number' + 1}
        )
    )
)

Stay tuned for the remaining 4 tips!

Recent tips

Leave a Reply