Views:

Overview

Custom Pages within model-driven Microsoft Dataverse apps are a great way to build pop-up dialogs that help with user productivity. Combining this with the power of Decision Tables enables you to easily add complex logic to your Custom Pages. In this article, we'll show you how to call a custom page from a list of records and then execute Decision Table logic from a button, returning messages to be displayed on the Custom Page.

The scenario for this example allows a user to select multiple opportunities and then change the Owner and/or change the Stage in the Business Process Flow. 

 

Rules for Updating Opportunities via Custom Page and Decision Tables

Rule #Description
1

When a user selects one or more Opportunities from the list, show a command button that will open a custom page as a dialog.

2

When a new Owner is selected the Opportunities are updated with the new Owner.

3

When a new Stage is selected the Opportunities are moved to the selected Stage in the Business Process Flow.

4

Messages returned from the North52 Decision Table are displayed on the Custom Page.

5

When the Custom Page is Closed, refresh the grid to reflect the changes.

 

North52 Decision Suite Solution

The North52 Decision Suite solution works like this:

  • When a user selects one or more Opportunities from the list, show a command button that will open a custom page as a dialog
  • User selects a new Owner and/or a new Stage, and then checks the box to confirm, enabling a button to apply the changes.
  • On click of the button, the Owner and/or Stage details are passed to a North52 Formula using a Power Automate Flow
  • The Formula executes via a Custom Action, and applies the rules defined in the Decision Table, returning messages as JSON
  • The Custom Page displays the messages 

Set up Global Action, Formula, Custom Page and Command Bar

If there are multiple parts to the North52 BPA solution, identify them in the H2 heading above and then provide instructions under Heading 3 headings below.

Global Action

To enable rules to be executed from the Custom Page via Power Automate we need to set up a Global Action.

  • From within your Solution, select New > Automation > Process > Action
    • Set Name to Process Opportunities on Click
    • Select None for Add to
    • Click Create
  • Set up two Process Arguments:
    • JSONPayloadIn
      • Set Name to JSONPayloadIn
      • Set Type to String
      • Set Direction to Input
    • JSONPayloadOut
      • Set Name to JSONPayloadOut
      • Set Type to String
      • Set Direction to Output
  • Click Save
  • Click Activate

Global Action Setting

Formula

  • Open the North52 App
  • Navigate to Business Process Activities > Formulas
  • Create a new formula, setting the following values in the Formula Guide:
    • Source Entity set to N52 Command
    • Set Formula Type to Action
    • Select the Decision Table editor
  • Change the Name of the formula to Custom Page Dialog - Action - Process Opportunities On Click
  • Click Save

Set Up Global Calculations

The Global Calculations will parse the JSON received from the Custom Page (via the Power Automate Flow).

  • Select the Source tab
  • Click on Global Calculations
    • This will set the Decision Table editor to Advanced Mode and open the Global Calculations sheet. You can also press F4 or right-click on a Decision Sheet > Operations > Toggle Advanced mode to reveal the Global Calculations sheet
  • Create 5 Global Calculations:
    • PowerAppJSON, with a Calculation Value of SetVar('responsecontent',[north52_command.JSONPayloadIn])
    • PowerAppJSON, with a Calculation Value of SetVar('responsecontent',GetVarJsonValue('[0]'))
    • Selected Records, with a Calculation Value of ConvertListToEntityCollection(GetVarJsonValue('SelectedRecordIds'), ',')
    • Selected Owner Id, with a Calculation Value of GetVarJsonValue('SelectedOwnerId')
    • Selected BPF Stage Name, with a Calculation Value of GetVarJsonValue('SelectedBPFStageName')

Global Calculations - North52 Business Rules Engine for Microsoft Dataverse

Set up Decision Sheet to Find and Update the Opportunity Records

  • Sheet Set Up
    • Select the first Decision Sheet and rename (double-click sheet tab) to Find and Update Records
    • To enable this sheet to execute each row for each record found, right-click on the sheet and select Hit Policy > Exit this Decision Table of First Match (should be unchecked)
    • To enable this sheet to update the relevant Opportunity, right-click on the sheet and select Set Sheet Options > Use UpdateCreateRecordById
  • Column Set Up
    • Right-click on the sheet and select Insert > Insert ForEachRecord
      • Select cell A2, then select Selected Records from Global Calculations in the Source tree 
    • Right-click column B and Insert > Insert Condition
      • Select cell B2, then select Selected Owner Id from Global Calculations 
      • Select cell C2, then select Selected BPF Stage Name from Global Calculations 
    • Right-click column D and Insert > Insert Inline Calculation
      • Select cell D2, then enter Name​​
    • Right-click column E and Insert > Insert Inline Calculation
      • Select cell D2, then enter Messages JSON
    • Select columns G and H, right-click and select Insert > Insert Action
      • Select the Explore tab
      • Enter Opportunity in the Search data model... box, press Enter
      • Expand the Opportunity node
        • Select cell F2, then from under the Opportunity node select Opportunity
        • Select cell G2, then from under the Opportunity node select Owner
      • Select cell H2, then enter Set BPF Stage
  • Row Set Up
    • In cell D4 enter FindValueQuickName('opportunity',CurrentRecord('id'))
    • Select cell B5, then control-click the ContainsData function from the Functions tab to enter {{{ContainsData}}}
    • In cell E5, enter:
      SetVarAppendJArray('Messages',
        CreateJObject(
          CreateJProperty('Message', GetVar('Name') + ' Opportunity owner updated.')
        )
      ) 
    • In cell F5, enter CurrentRecord('id') - this is the GUID of the current Opportunity to update
    • In cell G5, enter 'systemuser|' + {Selected Owner Id} - for polymorphic lookups, we need to set the entity schema name in front of the GUID
    • Select cell C6, then control-click the ContainsData function from the Functions tab to enter {{{ContainsData}}}
    • In cell E6, enter:
      SetVarAppendJArray('Messages',
        CreateJObject(
          CreateJProperty('Message', GetVar('Name') + ' Opportunity moved to ' + {Selected BPF Stage Name} + ' stage.')
        )
      ) 
    • In cell H6, enter BPSetActiveStageSS('opportunity',CurrentRecord('id'),'Opportunity Sales Process',{Selected BPF Stage Name}) - to define this you can use the function wizard by shift-clicking the function name from the Functions tab
    • Create a Comments column in column I to describe the actions of each row:
      • Row 4: Find Opp Name
      • Row 5: Set New Owner
      • Row 6: Move BPF Stage

Decision Tables - North52 Business Rules Engine for Microsoft Dataverse

Create Decision Sheet to Send Messages back to Custom Page

  • Right-click on the Decision Sheet and select Insert > Insert Decision Table
  • Rename the new sheet Action Output
  • Select the condition column A, right-click and select Delete > Delete Column - there are no conditions for this sheet
  • Select cell A2, select the Source tab, expand Processes > Actions > none >  n52demo_ProcessOpportunitiesOnClick - note the prefix for your Action will be different
    • Click on Out: JSONPayloadOut ( String - false ) to add it to cell A2
  • Select cell A4 and enter the following
    ToString(
      CreateJObject(
        CreateJProperty('Messages',
          GetVar('Messages JSON')
        )
      )
    )
  • Click Save, we are now ready to call this from the Custom Page

Decision Table - North52 Business Rules Engine for Microsoft Dynamics 365

Custom Page

  • From within your Solution create a new Custom Page called Custom Page - Process Opportunities
  • In our example we have enabled the Enable multiple screens from Settings > Display. This allows for to create screens for Success and Error messages. A similar effect could be done by having layered elements that cover the main screen.

Load Screen

  • The first screen in our Custom Page is called Screen_ProcessOpportunities, on this screen we have:
    • The OnVisible property is set to:
      Custom Page OnVisible Property - North52 Business Rules Engine for Microsoft Dataverse
    • Change the Owner Combo Box, with the Items linked to the System User table
    • Move Business Process Flow Stage Combo Box, with items linked to a collection called BPF Stage
    • Confirm Check Box to enable the button to call North52
    • Button to Call North52
      • DisplayMode property is set to If(Checkbox_Confirm_PO.Checked = true, "edit", ButtonStatePO)
      • Text property is set to ButtonTextPO
      • OnSelect property is set to:
        Custom Page Button OnSelect - North52 Business Rules Engine for Microsoft Dataverse
      • The FormulaData Collection defines what is sent to the North52 Formula - you will notice the names of the properties are used in the Global Calculations
      • The CallNorth52-ProcessOpportunitiesOnClick executes the Flow which calls the North52 Formula:
        Flow to call North52 Formula - Business Rules Engine for Microsoft Dataverse
    • Cancel button to close the screen
      • OnSelect property is set to Back()

Success Screen

The Success Screen is navigated to when the North52 Formula returns messages that are stored in the North52RulesMessages collection.

  • When there is data the Gallery_Messages_Success will show the messages from the North52RulesMessages collection - below shows the page in Edit mode:
    Custom Page Success Screen - North52 Business Rules Engine for Microsoft Dynamics 365

Error Screen

The Error Screen is navigated to when the North52 Formula does not return messages i.e. the North52RulesMessages collection is empty.

  • The error message will be displayed in the selected label:
    Error Screen - North52 Business Rules Engine for Microsoft Dynamics 365

Command Bar

For users to be able to open the Custom Page we need to create a button on the Command Bar.

  • Open the model driven app editor
  • Click Add Page to add your custom page to the App - this is important, otherwise your page won't load!
  • Select Edit command bar, by clicking the ellipsis icon to right of Opportunity in the Pages section
    Edit Command Bar - North52 Business Rules Engine for Microsoft Dataverse
  • Select the Main grid command bar to edit
  • Select the position in the command bar where you would like your button, the select New > Command bar
  • Complete the command options:
    • Label: Enter the name to be displayed for your button
    • Icon: Select an Icon if you would like to show one
    • Action: Select Run JavaScript
    • Library: Add the North52 Quick Ribbon library and select north52_quick_ribbon.js 
    • For the Function name: Enter N52QuickRibbon.OpenCustomPage
    • Add the following Parameters in this order (all six need to be created):
      • Parameter 1 - Type: String, Value: schema name of the custom page e.g. n52demo_custompagedemo_21c06
      • Parameter 2 - Type: String, Value: name to show on the title bar of the custom page e.g. Opportunity Dialog
      • Parameter 3 - Type: SelectedControlSelectedItemIds
      • Parameter 4 - Type: String, Value: the name of the start screen in the custom page (can be left blank to default to first screen)
      • Parameter 5 - Type: SelectedControl - this enables the grid to be refreshed when the custom page is closed
      • Parameter 6 - Type: String, Value: comma separated list of navigation options, defaults to 2,1,50,%,80,% if left blank, options:
        1. Target, 1 opens page inline, 2 to open as dialog
        2. Position, 1 opens dialog in center, 2 opens dialog on the far side
        3. Width value, number
        4. Width unit, % or px
        5. Height value, number
        6. Height unit, % or px
    • Visibility: Select Show on condition from formula
      • Enter If(CountRows(Self.Selected.AllItems)>0,true,false) so that the button is only visible if items are selected
  • The Command bar will look similar to this:
    Edit Command bar - North52 Business Rules Engine for Microsoft Dataverse
  • Save and Publish

Testing

Open your App and check that the new button is showing after selecting one or more Opportunity records. Click the button to open the dialog and complete the options on the custom page.

Click the image below to re-run the animation:

Custom Page Test - North52 Business Rules Engine for Microsoft Dynamics 365