Views:

Overview

There are many scenarios when you need to build custom dialogs to meet your business requirements. With the North52 business rules engine for Microsoft Dynamics 365 we make it easy to create a custom dialog using standard forms and North52 functions.

In this example we are going to provide functionality to allow multiple Opportunity records to have their Rating and Sales Team updated. For another example of updating multiple Opportunities via a custom dialog form, see this knowledge article.

 

Rules for Custom Close Opportunity Dialog

Rule #Description
1

When a user selects one or more Opportunities from the main grid they can update the Opportunity using a custom ribbon button and custom form.  Clicking the button opens a dialog form with Rating and Reset Sales Team fields and a subgrid showing Users.

2

The user can optionally choose to select a Rating value to update the Rating.   

3

The user can optionally choose to Reset the Sales Team (remove all current connections).

4

The user can select one or more Users from the subgrid which will then be connected to the Opportunity with a role of Sales Professional.

5

The user then clicks the North52 Quick Button Update Records, which calls a North52 Formula to update the selected Opportunities. After processing the form is updated with a Messages section detailing the updates that were done. 

 

North52 Decision Suite Solution

The North52 Decision Suite solution works like this (note you need Business Process Activities v1.0.0.642, Quick Button v9.30 and Quick Ribbon v9.30 or later to build this functionality):

  • A custom form is set up on the Opportunity table which is configured with a North52 Quick Button
  • A custom ribbon button is set up to open the custom form using the North52 Quick Ribbon functionality
  • A Formula is set up on the Opportunity Form which after being opened with the custom ribbon button:
    • Sets initial field values and requirements on load
  • A Formula is set up on the Opportunity table which is called by the North52 Quick Button:
    • Updates the selected Opportunity records with the values from the form passed into the Formula from the Quick Button
    • Calls a Library Calculation Formula to create Connection records for each selected user
      • Optionally existing Connection records are removed
      • Only creates a new Connection record if one does not exist already
    • Once the Opportunity records have been updated the Formula sends Message data back to the custom dialog form to be displayed

Set up Custom Form, Ribbon Button, and Formulas

There are multiple components needed to build the custom dialog form to close an Opportunity. The steps are outlined in the following sections.

Custom Form

The custom form will be opened as a dialog window to allow the user to input values. It will not save data like a traditional form as we only use it to capture information to be passed to a Formula which then processes the information. The steps to allow this to happen are outlined below:

  • Create a new Main Form called Bulk Edit Form 
  • Remove tabs and sections so that the form has only a single tab and section
    • To remove required fields from the form e.g. Owner, add a column to a Tab and move all required fields to this column. Then remove the column from the Tab. The required fields will be removed with the column.
    • Rename the remaining section to Update Sales Team and Rating
  • Create a new Single Line of Text field called Bulk Edit Guids, add it to the form and check the Hide option - this will be used to contain the Opportunity GUIDs of the selected records in the main grid
  • Add the existing field Rating to the form
  • Create a new Yes/No field called Reset Sales Team?, and add it to the form
  • Add a Subgrid component, and set the Label and Name to Users
  • Add a HTML Web Resource and select North52 Quick Button Unified Interface web resource (the North52 Quick Button solution needs to have been previously installed)
    • In the Custom parameter data field enter (See the North52 Quick Button documentation for details on these parameters):
      ab1|✓ Update Records|pure-button button-success|submitmodevisible||button-subgrid-notrequired|Users||Are you sure you want to process these records?
    • Set the Component Height option to 1 row
    • Set the Scrolling option to Never
    • Uncheck the Display Border option
  • Add a new 1-column section component and set the Label to Messages and Name to Summary Messages
  • Create a new Multiple Lines of Text field called Bulk Edit Form Message, add it to the Messages section
    • Check the Hide Label option
    • Set the Form field height to 20 rows
  • Add a HTML Web Resource and select North52 Quick Button Unified Interface web resource (the North52 Quick Button solution needs to have been previously installed)
    • In the Custom parameter data field enter (See the North52 Quick Button documentation for details on these parameters - Close() is a reserved short code parameter which does not call a Formula but closes the window):
      Close()|X Close Window|pure-button button-warning
    • Set the Component Height option to 1 row
    • Set the Scrolling option to Never
    • Uncheck the Display Border option
  • Set both Sections, the Tab and Related to be Hidden (use the Show Hidden toggle to display even when set to hidden)
  • Add event functions to the form to remove the chrome and disable save (this allows the form to behave like a dialog when interacting with North52 Formulas):
    • Under the On Save section click on Event Handler
      • Select the Javascript Command Execution (north52_/javascript/commandexecution) library (you will need to add this to the form, search for command execution)
      • For Function enter North52.CommandExecution.TurnOffAutoSave
      • Check the Pass execution context as first parameter option
    • Under the On Load section click on Event Handler
      • Select the Javascript Command Execution library
      • For Function enter North52.CommandExecution.HideChrome
      • Check the Pass execution context as first parameter option
    • Under the On Load section click on Event Handler
      • Select the Javascript Command Execution library
      • For Function enter North52.CommandExecution.SetSubmitModeNeverAllFields
      • Check the Pass execution context as first parameter option
  • Click Save and Publish

Ribbon Button

The custom ribbon button needs to be added your App:

  • Open the App in which you wish to place the custom ribbon button
  • Edit the command bar for the Opportunities view
  • Select the Main grid
  • Add a new Command button in the desired position with the following settings:
    • Label: Custom Bulk Edit Dialog
    • Icon: Use Icon, Edit
    • Action: Run JavaScript
    • Library: north52_quick_ribbon.js
    • Function Name: N52QuickRibbon.OpenForm
    • Add 7 Parameters in the following order:
      1. PrimaryControl
      2. SelectedControlSelectedItemIds
      3. String, n52demo_bulkeditguids (this is the field that will be used to pass selected record GUIDs to the Formula)
      4. String, opportunity (schema table name)
      5. String, GUID (guid of the custom form to open when button is clicked)
      6. String, Bulk Edit Opportunities (title to be displayed on modal popup form)
      7. String, refreshlist (this refreshes the list when the modal form is closed)
    • Visibility: Show on condition of formula
    • Formula bar: !IsEmpty(Self.Selected.AllItems)
    • Click Save and Publish

 

    Command settings 1 - North52 business rules engine for Dynamics 365 Command settings 2 - North52 business rules engine for Dynamics 365

    Formula - UI Rules

    This Formula controls the user interface rules. To create the 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 Opportunity
      • Set Formula Type to ClientSide - Perform Action
      • Select the Decision Table editor
    • Change the Name of the formula to Opportunity - Modal Demo - Bulk Update Form UI
    • Click Save
    • Expand Source & Target
    • Ctrl-Select Onload and Bulk Edit Form Message under the *** Bulk Edit Form Events *** section

    Sheet - DecisionTable

    • Select cell A2, then from the Source tree select the Bulk Edit Form Message column
      • Select cell A4, then from the Functions list Ctrl+Click the ContainsData function
    • Select columns B to E, right-click and select Insert > Insert Action
    • Select cell B2, then from the Source tree select the Rating column
      • Select cell B5, then from the Functions list Ctrl+Click the ClearFields function, this will enter {{{ClearFields}}} into the cell  
    • Select cell C2 and enter Show/Hide Edit
      • Select cell C4, then from the Function list Shift+Click the HideSections function to open the Function Wizard
        • Ignore the Friendly Name field
        • Click the Search Icon for the Sections field and select Bulk Edit Form > Summary > Update Sales Team and Rating
        • Click Generate
        • HideSections('Summary.bulkedit') is entered into the cell
    • Copy cell C4 to C5 and change Hide to Show so the contents are ShowSections('Summary.bulkedit') - you could also use the function wizard as per the previous step 
    • Select cell D2 and enter Show/Hide Message
      • Select cell D4, then from the Function list Shift+Click the ShowSections function to open the Function Wizard
        • Ignore the Friendly Name field
        • Click the Search Icon for the Sections field and select Bulk Edit Form > Summary > Messages
        • Click Generate
        • ShowSections('Summary.Summary_Messages') is entered into the cell
    • Copy cell D4 to D5 and change Show to Hide so the contents are HideSections('Summary.Summary_Messages')
    • Select cell E2 and enter Show Tab (the reason why we hide the tab on the form in the designer and show it here as the last action is to prevent flicker of elements as the rules are applied)
      • Select cell E5, then from the Function list Shift+Click the ShowTabs function to open the Function Wizard
        • Ignore the Friendly Name field
        • Click the Search Icon for the Tabs field and select Bulk Edit Form > Summary
        • Click Generate
        • ShowTabs('Summary') is entered into the cell
    • Save the Formula

    Publish Formula

    When binding a ClientSide Formula to Form events, the Formula needs to be Published. Select Commands > Publish Formula

    Formula - Quick Button Rules

    This Formula controls the Opportunity update rules initiated by the Update Records Quick Button. It has two sheets;  Update Opportunities and Show Message. To create the 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 Opportunity
      • Set Formula Type to ClientSide - Calculation
      • Select the Decision Table editor
    • Change the Name of the formula to Opportunity - Modal Demo - Bulk Update Quick Button
    • In the Form header enter ab1 in the Short Code field (this is to match the short code entered in the Quick Button web resource parameters above)
    • Click Save

    Sheet - Update Opportunities

    This sheet loops over the selected Opportunities and depending on the information supplied on the Bulk Edit Form updates the Opportunity Rating and deletes and/or creates associated Connection records.

    • Double click the sheet name and rename to Update Opportunities
    • Right-click on the sheet and select Set Sheet Options > Use UpdateCreateRecordById
    • Select column A, right-click on the sheet and select Insert > ForEachRecord 
    • In cell A2 enter Selected Opps
    • Right-click on the sheet and select Operations > Toggle Advanced Mode (or press function key F4) to show the hidden row 3
    • Select cell A3, expand the cell editor, then from the Functions list click ConvertListToEntityCollection
      • Delete the placeholder text 'list' and select Bulk Edit Guids column from the Source tab to enter [opportunity.n52demo_bulkeditguids] into the editor
      • Replace the separator placeholder text with a comma ,
      • Close the cell editor
      • Cell A3 should now be ConvertListToEntityCollection([opportunity.n52demo_bulkeditguids], ',')
    • Select columns B and C, right-click and select Insert > Insert Condition to add two more condition columns
    • Select cell B2, then from the Source tree select the Rating column
      • Select cell B5, then from the Functions list Ctrl+Click the ContainsData function, this will enter {{{ContainsData}}} into the cell
    • Select cell C2, then from the Source tree select the Bulk Edit Reset Sales Team column
      • Select cell C6, then from the Source tree expand Bulk Edit Reset Sales Team and select Yes
    • Select cell D2, then enter Selected Users
      • Select cell D3, then enter [opportunity.n52subgridentitycollection] (n52subgridentitycollection is a North52 specific "virtual" field which contains the comma separated GUIDs of the records selected on the Form Subgrid) 
      • Select cell D7, then from the Functions list Ctrl+Click the ContainsData function
    • Select column E, right-click on the sheet and select Insert > Insert Inline Calculation (==) 
      • Select cell E2, then enter OpportunityName
      • Select cell E4, then from the Function list Shift+Click the FindValueQuickName function to open the Function Wizard
        • Ignore the Friendly Name field
        • Click the Search Icon for the Entity Name field and select Opportunity
        • In the ID of Record to Find Name of field enter CurrentRecord('id') (this is the GUID of the current Opportunity record within the ForEachRecord loop)
        • Click Generate
        • FindValueQuickName('opportunity',CurrentRecord('id')) is entered in the cell
    • Select column F, right-click on the sheet and select Insert > Insert SetVarConcat Calculation (*-) 
      • Select cell F2, then enter Messages
      • Select cell F4, enter '---- ' + {OpportunityName} + ' ----\n' (the {OpportunityName} variable could have been added from the Source tab: Source > Decision Table Calculations > Update Opportunities > OpportunityName)
      • Select cell F5, enter '* Rating updated to ' + {Rating {Name}} + '\n' (the {Rating {Name}} field reference could have been added from the Source tab: Source > Rating {Name}
      • Select cell F6, enter '* Sales Team Reset \n'
      • Select cell F7, enter '* Sales Team updates: \n'
      • Select cell F8, enter '\n' (\n adds a line break after all the messages)
    • Select columns G to I, right-click and select Insert > Insert Action to add three more Action columns
    • Select cell G2, then from the Source tree select the Opportunity column
      • Select cell G5, then enter CurrentRecord('id')
    • Select cell H2, then from the Source tree select the Rating {Value} column
      • Select cell H5, then from the Source select Rating {Value} and {Rating {Value}} will be entered into the cell
    • Select cell I2, then enter Remove Existing Sales Team (this next section sets up what is required to delete the existing Sales Team Connection records) 
      • Select the Global FetchXml sheet (ensure that you are in Advanced Mode - see step above)
        • Select cell A2 and enter FindExistingSalesTeamConnections
        • Select cell B2 and expand the cell editor, and copy/paste the following Fetch XML:
          <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
            <entity name="connection">
              <attribute name="record2id" />
              <attribute name="record2roleid" />
              <attribute name="connectionid" />
              <order attribute="record2id" descending="false" />
              <filter type="and">
                <condition attribute="record1id" operator="eq"  value="{0}" />
                <condition attribute="record2roleid" operator="eq" uiname="Sales Professional" uitype="connectionrole" value="{1}" />
              </filter>
            </entity>
          </fetch>
        • Close the cell editor
      • Select the Update Opportunities sheet
    • Select cell I5 and expand the cell editor
      • Copy/paste the following:
        DeleteRecordsFD(
          'FindExistingSalesTeamConnections', 
          true, 
          SetParams(
            CurrentRecord('id'),
            FindValueQuickId('connectionrole','Sales Professional')
          )
        )
      • Close the cell editor
    • Select cell J2, then enter Update Sales Team (this next section sets up what is required to create new Sales Team Connection records) 
    • Select cell J6 and expand the cell editor
      • Copy/paste the following (we will create the Library Calculation Formula with Short Code 68R in the next section - the following executes the Library Calculation Formula by passing in the selected users from the form subgrid, returns the messages from the Formula calculation and add them to the Messages variable in this Formula) :
        SetVarConcat('Messages', 
          ExecuteFormula('68R', CurrentRecord('id'), SetFormulaParameters('selectedusers', [opportunity.n52subgridentitycollection]), 'true' )
        )
      • Close the cell editor
    • Click Save

    Sheet - Show Message

    This sheet sets the value in the Bulk Edit Form Message field on the form. The UI Formula above then will display the section when this field contains a value.

    • Right-click on the sheet and select Insert > Insert Decision Table
    • Right-click on the sheet and select Set Sheet Options > Use ClientSide
    • Double click the sheet tab and enter Show Message
    • Select cell B2, then from the Source tab select the column Bulk Edit Form Message
    • Select cell B4, then from the Source tab select Decision Table Calculations > Update Opportunities > {Messages}
    • Click Save

    Library Calculation Formula - Create Connections

    This Formula creates Connection records between the Opportunity and the selected Users with a role of Sales Professional. To create the 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 Opportunity
      • Set Formula Type to Library Calculation
      • Select the Decision Table editor
    • Change the Name of the formula to Opportunity - Modal Demo - Create Connections Library Calculation
    • In the Form header enter 68R in the Short Code field (this is to match the short code entered in the Opportunity - Modal Demo - Bulk Update Quick Button Formula above)
    • Click Save

    Sheet - Add Selected Users to Sales Team

    This sheet loops over the selected Users and creates a Connection record for each one.

    • Double click the sheet name and rename to Add Selected Users to Sales Team
    • Right-click on the sheet and select Set Sheet Options > Use CreateRecord
    • Select column A, right-click on the sheet and select Insert > ForEachRecord 
    • In cell A2 enter Selected Users
    • Right-click on the sheet and select Operations > Toggle Advanced Mode (or press function key F4) to show the hidden row 3
    • Select cell A3, expand the cell editor, then from the Functions list click ConvertListToEntityCollection  
      • Delete the placeholder text 'list' and enter [opportunity.selectedusers] into the editor (this is the selectedusers parameter passed in when executing this Formula - it referenced as a "virtual" opportunity column [opportunity.selectedusers])
      • Replace the separator placeholder text with a comma ,
      • Close the cell editor
      • Cell A3 should now be ConvertListToEntityCollection([opportunity.selectedusers], ',')
    • Select cell B2 and enter Find Existing Connection
      • Select cell B3, then from the Function list Shift+Click the FindValue function to open the Function Wizard
        • Ignore the Friendly Name field
        • Entity Name, click the Search Icon and select Connections
        • Where Attribute, click the Search Icon and select Connected From and Connected To
        • Equals Value, click the Search Icon and select Opportunity, then put in a comma followed by CurrentRecord('id') (this is the GUID of the current User record within the ForEachRecord loop)
        • Select Attribute, click the Search Icon and select Connection
        • Default Value, leave as ?
        • No-Lock, leave as true
        • Click Generate
      • The value in the cell should be FindValue('connection',SetFindAnd( 'record1id','record2id' ) ,SetFindAnd( [opportunity.opportunityid], CurrentRecord('id') ) ,'connectionid','?','true')
      • Select cell B4, then from the Functions list Ctrl+Click the DoesNotContainsData function, this will enter {{{DoesNotContainsData}}} into the cell
      • Select cell B5, then from the Functions list Ctrl+Click the ContainsData function, this will enter {{{ContainsData}}} into the cell
    • Select column C, right-click on the sheet and select Insert > Insert SetVarConcat Calculation (*-) 
      • Select cell C4, then enter '  ✅ ' + FindValueQuickName('systemuser', CurrentRecord('id')) + ' Added \n'
      • Select cell C4, then enter '  ❌ ' + FindValueQuickName('systemuser', CurrentRecord('id')) + ' NOT Added (already on Sales Team) \n'
    • Select columns D to G, right-click and select Insert > Insert Action to add four more Action columns
    • Select the Explore tab, under Explore Data Model search for Connection
      • Expand the Connection node
      • Select cell D2, click on Connected From (Value)
        • Select cell D4, enter 'opportunity|' + then click on Opportunity from the Source tab (Connected From is a polymorphic lookup field so we need to specify the table name followed by a | here)
      • Select cell E2, click on Type From (Value) from the Explore tab
        • Select cell E4, expand Type From (Value) and select Opportunity
      • Select cell F2, click on Connected To (Value)
        • Select cell F4, enter 'systemuser|' + CurrentRecord('id') 
      • Select cell G2, click on Type To (Value) from the Explore tab
        • Select cell E4, expand Type To (Value) and select User
      • Select cell H2, click on Role To (Value) from the Explore tab
        • Select cell E4, enter 'Sales Professional'
    • Click Save

    Sheet - Return Message

    This sheet sets the returns the Message from the Library Calculation back to the calling Formula.

    • Right-click on the sheet and select Insert > Insert Decision Table
    • Right-click on the sheet and select Set Sheet Options > Use ClientSide
    • Double click the sheet tab and enter Return Message
    • Select cell B4, then from the Source tab select Decision Table Calculations > Add Selected Users to Sales Team > {Message}
    • Click Save

    Testing

    Open the App where you added the command button and navigate to the Opportunities main grid. Select an open Opportunity record and click the Custom Close Won/Loss ribbon button (you may need to refresh your browser several times for the published changes to show).