Thursday, August 19, 2021

Version Control & Warning

I have kept hoping that Microsoft would deliver a standardized method for catching users running old versions of the application.  However, I am giving up on waiting on them to deliver on this.

While the platform generally updates automatically, some user's devices or browsers can cache the application and wind up stuck with a prior version when they first open it instead of immediately refreshing/reloading.

This is a fairly simple method to help you build out your application and catch if/when this happens so that users will be told to close/re-open/refresh.

Version Control List

How we manage this is by having a SharePoint list (or you could do a CDS) that is globally shared for Read access.  

Basic SharePoint Version List

You'll need to set this list to be visible to whomever also uses your application.  You can do this through the List configuration (gear icon in the upper-right on your SharePoint List | List Settings | Permissions for this List) and give them Read access to your list.

In the above example, I've created list that includes:

  • Title (default and what I'm using as a short description)
  • userWarning (the text I plan to show the end user and instructions)
  • changeDetails (information about the changes made)
  • version (number field w/ 2 decimal places)
I am assuming we will create new versions as we go and might give additional/new instructions to the end-users depending upon how users respond to the instructions given.

We will read this list from our App(s) and compare what the App thinks is the current version and what SharePoint thinks is the current version.

Reading the Version

Above, I created a SharePoint list named appVersions.  Add the connection to your app using View | Datasources and select from the type/name of your own data source.  This will allow us to read from the List and compare our App's version to what the List says is the latest one.

Alter your starting code (I highly suggest no longer using the OnStart property) for the app to be the following while changing the green text to reflect the version of your app:

Set(
    appVersion,
    1.02
);
ClearCollect(//Get current version from SharePoint list
    currentVersion,
    First(
        Sort(
            appVersions,
            version,
            Descending
        )
    )
);
Set(//Mark if the app is running the wrong version
    appVersionOutOfDate,
    First(currentVersion).version > appVersion
);


This gets the version and does the comparison for us to see if we're up to date or not.  It sets a variable appVersionOutOfDate to be true if any version in the list is greater than the version we have in our app.

We'll use this variable to control how our app behaves if the version running is incorrect.

Handling an Old Version

We cannot force a reload or an update on an end user's device.  However, we can give them instructions on the steps they should take to force a refresh.

In this scenario, I've added in a few controls that will only appear if appVersionOutOfDate=true.

I've laid out:

  • warningVersionBckgrnd1a Label w/ no text and a Fill of RGBA(0, 0, 0, .1)
  • warningVersionBckgrnd2: a Text Input w/ no text, a DisplayMode of View, and all of the corner Radius values of 15
  • warningVersionHTML: an HTML text field that we will tie to the values retrieved from our SharePoint list
  • warningVersionStopImg: for fun I'm doing an SVG as raw text vs. importing the image

All of these are put into a Group named warningVersionGrp.  The Visible setting for all of these is changed to appVersionOutOfDate.

If we put these items in the order I have above and at the top of the application, then when the value of appVersionOutOfDate is true we'll show these fields and it will block interaction with any other control.  

Text Details

The warningVersionHTML field is populated by the following code within the HTML setting:

Substitute(

    First(currentVersion).userWarning,
    "[[appVersion]]",
    Text(appVersion)
) & "<hr>" & First(currentVersion).version & ": " & First(currentVersion).changeDetails

When we started the app, we populated the currentVersion Collection with details on the latest version of the application as defined by the SharePoint list.  

This code is pulling those values out and using them to populate our field

Image Details

As I stated above, instead of importing this image, I decided to instead play around w/ doing inline SVG vlaues.  The contents of the Image setting for warningVersionStopImg is the following value:

"data:image/svg+xml;utf8, " & EncodeUrl("
<svg...(all the gobbledygook between the <svg></svg> tags w/ double quotes converted to single quotes...</svg>
")

This actually will populate the Image without us having to import the image into our app.

SVG images are just raw text if you open them in Notepad or similar.  Editing them to change the double quotes to single ones and to cut everything between and including the <svg></svg> tags in the above logic will allow you to simply cut/paste the text, or even just have it sitting in a SharePoint list or Excel file as a LookUp().

Final Thoughts

Microsoft will eventually deliver something for us in this space so I wouldn't waste too many brain cells on it.  However, this is probably the easiest way you can deploy this until Microsoft allows us a way to query/reference the dynamically created Version they create when you republish your application.

This is also reasonably flexible enough that you can copy/paste all of this for each of your applications to have their own Version list, or create some uber master list and include application IDs in your table.

No comments:

Post a Comment

Because some d-bag is throwing 'bot posts at my blog I've turned on full Moderation. If your comment doesn't show up immediately then that's why.