Views:

Overview

Often when using Microsoft Power Apps Portals your data collection requirements and rules are more complex than can be configured using standard functionality. North52's advanced business rules engine for Microsoft Dynamics 365 and Power Apps Portals provides no-code tools to help address this problem.

In this example we use the scenario of a hospital admission questionnaire. There are several key requirements that need to be addressed using North52 functionality:

Requirements for an advanced Patient Admission Form

Req # Description
1

Form structure changes depending on when the form was first submitted

  • For example, new fields, sections, and tabs may be added and others removed, but if you are viewing an older submission you want to see the form as it was when the data was submitted without the extra fields 
2

Validation rules only to be applied when the user is ready to submit their information

  • When completing complex forms sometimes you don't have all the data to hand, so you need to answer it as best you can, save it, and then come back later to complete it. You don't want validation logic to be applied for mandatory fields until the user has indicated that they are ready to submit. 
3

Form logic/rules need to be easily created and maintained without writing code

4

Form logic/rules need to be applied to both Portal Forms and Model-Driven App forms

North52 Decision Suite Solution

The North52 Decision Suite solution has three main parts:

  1. A Formula with multiple Decision Tables to render the Quick Tile navigation according to:
    • The date of the submission
    • The currently selected Form
    • The submission status (Draft/Completed) of the currently selected Form
  2. Formulas for each Tab (associated to a Basic Form) containing Decision Tables for display rules and validation rules
  3. A custom Web Template to render the appropriate Basic From depending on what has been selected in the Quick Tile navigation

There are also Formulas for 'admin' activities e.g. Setting the name of the record and submission date on create.

Set up Model Driven Form, Portal Components and North52 Formulas

Model Driven Form

The first part to set up is the Model Driven Form that will be used by the Portal Basic Forms to render the questionnaire sections on the portal page. For each section of the questionnaire to be displayed on portal we create Tabs on the Model Driven Form as shown in the image below:

  • Each tab has a Draft/Completed status field that enables/disables rule and validation processing. This is also used to determine how much of the total questionnaire has been completed.

Portal Components

To enable partial saving of the questionnaire as a user progresses, and to support the dynamic display of parts of the questionnaire (i.e. the Tabs from the Model Driven Form) the portal components need to be set up as follows:

  • Two Web Pages - one for the initial create and one for the edits
  • A Basic Form set to the Details Tab for the initial Insert (record creation)
  • Basic Forms for each of the Tabs (in our example there are 12)
    • These do not redirect to another page on save - the Quick Tile rules determine the navigation
  • A Web Template to manage the dynamic display of the Forms

Web Template

The following is the Liquid/HTML for the Web Template. You can also see the style classes for altering the display of the Quick Tile navigation:

{%- assign formid = request.params.n52ParamFId -%}
<style>
.n52tileresult {
    font-size: 16px !important;
    text-align: left;
    line-height: normal;
    min-height: 32px;
    padding: 5px 5px 5px 10px;
}
.edit .n52tileresult {}
.draft .n52tileresult {}
.complete .n52tileresult {
    font-weight: normal;
}
.glyphicon.qtlink-icon {
    display: none;
}
</style>

<div class="container">
    <div class="page-heading">
        {% block breadcrumbs %}
            {% include 'Breadcrumbs' %}
        {% endblock %}
        {% block title %}
            {% include 'Page Header' %}
        {% endblock %}
    </div>
    <div class="row">
        <div class="col-md-12">
            {% include 'Page Copy' %}
        </div>
    </div>
    <div class="row">
        <div class="col-md-3" style="padding-top: 20px">
            <div class="n52_tiles" data-n52tile="ovg" data-n52loader="8"></div>
        </div>
        <div class="col-md-9" style="padding-top: 20px">
            {% block main %}
                {% if formid %}
                    {% entityform id: formid %}
                {% elsif page.adx_entityform %}
                    {% entityform id: page.adx_entityform.id %}
                {% endif %}
            {% endblock %}
        </div>
    </div>
</div>

The Quick Tile is added to the template using the following code:

<div class="n52_tiles" data-n52tile="ovg" data-n52loader="8"></div>

ovg is the Short Code of the Quick Tile Formula (see top right corner of first Decision Table image below) and will be replaced with your Formula Short Code in your template. 8 in the data-n52loader parameter means that 8 placeholder tiles are shown when it is loading - you can configure this value.

Formulas

There is one Formula with multiple Decision Table sheets for the Quick Tile navigation and a separate Formula for each of the Tabs that controls visibility and validation rules. These examples are shown below.

Quick Tile Formula

To display the form navigation and progress we use North52's Quick Tile functionality:

The Decision Table sheet below shows the rules for rendering the Details tile. There is full control over various aspects of the tile - see Column A for a description of what each row represents: 

The Progress Bar tile uses the Progress Bar functionality provided as part of the Power Apps Portals Bootstrap 3 templates. The Decision Table Sheet shown below shows how this is configured:

The HTML in the Result-13 column (cell B5) is as follows:

'<div class="progress">' +
  '<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="' + 
    [n52demo_patientadmission.n52demo_progresspercentage.0] + 
    '" aria-valuemin="0" aria-valuemax="100" style="width: ' + 
    [n52demo_patientadmission.n52demo_progresspercentage.0] + '%;">' +
    [n52demo_patientadmission.n52demo_progresspercentage.0] + '%' + 
  '</div>' +
'</div>'

See the Bootstrap 3 Progress Bar information for further details.

The last Decision Table sheet is used to control which navigation tiles are displayed depending on the submission date e.g. If the submission date was less than 1 April 2021 then row 7 would match and show a subset of the navigation tiles:

Formulas for selected Tab visibility and validation rules

To make maintenance easier we create a separate Formula for each of the Tabs which requires visibility and validation rules:

There are 3 Decision Table sheets in the Formula for the Smoking tab rules. The first Decision Sheet Current Smoking has these rules:

Rule # Description

1

Onload of the Form or on change of the Submission Status Smoking or Do you currently smoke? fields:

If the Submission Status Smoking field is Completed and the field Do you currently smoke? is set to Yes, then:

  • Show the Number of Smokes Per Day field
  • Set the Number of Smokes Per Day field to Required

2

Onload of the Form or on change of the Submission Status Smoking or Do you currently smoke? fields:

If the Submission Status Smoking field is Completed and the field Do you currently smoke? is set to Yes, then:

  • Show the Number of Smokes Per Day field
  • Set the Number of Smokes Per Day field to Not Required

3

Onload of the Form or on change of the Do you currently smoke? field:

If the field Do you currently smoke? is set to No, then:

  • Hide the Number of Smokes Per Day field
  • Set the Number of Smokes Per Day field to Not Required
  • Clear the Number of Smokes Per Day

The rules are implemented in the Formula as follows:

The second Decision Sheet Year Stopped has these rules:

Rule # Description
1

Onload of the Form or on change of the Submission Status Smoking or Have you smoked in the past? fields:

If the Submission Status Smoking field is Completed and the field Have you smoked in the past? is set to Yes, then:

  • Show the If you smoked in the past, year ceased field
  • Set the If you smoked in the past, year ceased field to Required
2

Onload of the Form or on change of the Submission Status Smoking or Have you smoked in the past? fields:

If the Submission Status Smoking field is Completed and the field Have you smoked in the past? is set to Yes, then:

  • Show the If you smoked in the past, year ceased field
  • Set the Number of Smokes Per Day field to Not Required
3

Onload of the Form or on change of the Have you smoked in the past? field:

If the field Have you smoked in the past? is set to No, then:

  • Hide the If you smoked in the past, year ceased field
  • Set the If you smoked in the past, year ceased field to Not Required
  • Clear the If you smoked in the past, year ceased

The rules are implemented in the Formula as follows:

The third Decision Sheet Year Stopped - Validation has these rules:

Rule # Description
1

Onload of the Form or on change of the If you smoked in the past, year ceased field:

If the If you smoked in the past, year ceased field Contains Data and is less than the current year minus 100, then:

  • Show an Error notification on the field that says Must be between [current year - 1000] and [current year] *
2

Onload of the Form or on change of the If you smoked in the past, year ceased field:

If the If you smoked in the past, year ceased field Contains Data and is more than the current year, then:

  • Show an Error notification on the field that says Must be between [current year - 1000] and [current year] *
3

Onload of the Form or on change of the If you smoked in the past, year ceased field:

If any of the conditions in the above rules are not met, then:

  • Clear the notifcation

* Note: When using the SetControlNotfication() function with Power Apps Portals a custom page validation is also added so if the user tries to submit the form an error message will be displayed (see animation below)  

The rules are implemented in the Formula as follows:

Testing

For the Smoking tab we can see the rules in action: