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.