Views:

Scenario Overview

In this scenario the business requirement for the customer was how to handle 2 different shifts of employees, 

  • A Day shift starting at 8 am, 
  • A Night shift starting at 8 pm. 

The Day shift should get access to Dynamics 365 from 8 am to 8 pm, but should be unable to log in from 8 pm to 8 am and vice versa for the Night shift.

Each user is assigned to the Day Shift or Night Shift based on an OptionSet in their user account.

North52 Decision Suite Solution

The North52 Decision Suite solution works like this,

  • A Global Action type process is created
  • An N52 Formula of type 'Process Genie' is created on the User entity and added to the Action
  • The N52 Formula checks if the time is before 9 am, if yes it will activate the days shift and deactivate the night shift, it after 9 am it will do the opposite
  • An N52 Schedule is created to run the action every twelve hours at 8 am and 8 pm

North52 Decision Suite Steps

The following set of steps outline how to create this Formula

  • Create a formula of type 'Process Genie' on the User entity
  • Copy and paste the formula below into the formula canvas
  • Created a new process of type 'Action - Global'
  • Add a North52 Process Genie step to it and add the short code from the formula to it
  • Create a new N52 Schedule of type 'Global Action' to run the Action
  • Save and test

The Process Created for the Process Genie




Note: The 'Process Name' field on the action must contain as the last word the exact same name as the Unique Name that Microsoft generates for you on the Action.
So for example 'Activate and Deactivate Work Shifts' becomes 'Activate and Deactivate Work Shifts new_ActivateAndDeactivateWorkShifts'

This is due to a bug when you execute Fetch-XML to lookup at run-time the unique name of the Action. We logged this bug on Connect with Microsoft but it has yet to be resolved. 

The Global Action

Please make sure you add the unique name to the end of the Process Name as per the above note.

Adding the Formula ShortCode to the Process Genie Step


The N52 Scheduler
   
Formula

/* If before 9 am */
  if(DateDiff(localdate(), localdatetime(), 'h') < 9, 
    /* Activate Day Shift, Deactivate Night Shift */
    SmartFlow(

      /* Activate Morning Shift */
      ForEachRecord(

        FindRecords('systemuser', 'new_shift',  '100000000', 'systemuserid', '50', true),

        UpdateRecord('systemuser',
          CurrentRecord('systemuserid'),
          SetAttributeStatus('0', '-1'))
      ),
      /* Deactivate Night Shift */
      ForEachRecord(

        FindRecords('systemuser', 'new_shift',  '100000001', 'systemuserid', '50', true),

        UpdateRecord('systemuser',
          CurrentRecord('systemuserid'),
          SetAttributeStatus('1', '-1'))
      )
    ),
    /* If not before 9 am, Activate Night Shift, Deactivate Day Shift */
    SmartFlow(      
      /* Deactivate Day Shift */
      ForEachRecord(

        FindRecords('systemuser', 'new_shift',  '100000000', 'systemuserid', '50', true),

        UpdateRecord('systemuser',
          CurrentRecord('systemuserid'),
          SetAttributeStatus('1', '-1'))
      ),
      /* Activate Night Shift */
      ForEachRecord(

        FindRecords('systemuser', 'new_shift',  '100000001', 'systemuserid', '50', true),

        UpdateRecord('systemuser',
          CurrentRecord('systemuserid'),
          SetAttributeStatus('0', '-1'))
      )
    )
  )

Wizard - FindValue

Please see below the wizard you can use to create the FindValue() function call used in this formula. 

Note you will need to have created the field new_shift beforehand and refreshed the formula by clicking N52 Commands > Refresh. 
 

Did you know?

North52 has over 500 functions to help you implement advanced business rules and complex decision logic

One of the biggest costs on most Microsoft Dynamics 365/CRM project is custom coding. This is where consultants or developers are invloved in writing 100’s if not thousand’s of lines of code in Javascript and/or C#.

The Formula Manager, part of the North52 Decision Suite is a business rules engine that aims to eliminate this custom coding by using simple formulas instead. It is significantly faster (up to 10 times) than writing custom code and you get the added bonus of lower cost updates if a business rule changes in the future (it is much faster and thus cheaper to change it using a Formula rather than custom code).

There are over 500 functions available in the North52 Decision Suite business rules engine!

Learn more about North52 Business Process Activities