Opening Hours from Dynamics in Copilot

Opening Hours from Dynamics in Copilot

Have you ever tried to access the Customer Service opening hours in Copilot? It’s not easily accessible through APIs or the dataverse action ‘List’. This is a working solution to get a true or false if the workstream is open right now

The usecase was as follows: From Copilot, is the customer service center open or closed. From my research I have not found this documented anywhere on the Microsoft documentation or anywhere else.

This was solved by using a flow action in Copilot Studio to check for the state of the calendar holding the opening hours.

The overview of the flow can be seen in the picture below:

Two variables was defined, one for keeping the final state and one for getting the time right now

The next stage was to get the opening hours from a named calendar and then to use this result to get the calendarid needed in the next stage

The column was fetched with the following code

first(outputs('List_openinghours')?['body/value'])?['msdyn_calendarid']

Then the input for the unbound action was composed with the following json

{
  "StartDate": "@{variables('timeNow')}",
  "EndDate": "@{variables('timeNow')}",
  "CalendarIds": [
    "@{outputs('Get_the_calendar')?['body/calendarid']}"
  ]
}

Then the unbound action «msdyn_loadCalendars» was used to get the status of the calendar at timeNow variable defined.

The result was parsed with the following schema

{
    "type": "object",
    "properties": {
        "@@odata.context": {
            "type": "string"
        },
        "CalendarEvents": {
            "type": "string"
        }
    }

The last part can probably be rewritten in a better way and to follow best practice, but this will be working as it is as well

Here are the parameters used for the different stages in the last picture

Get TimeCode

split(body('Parse_JSON')?['CalendarEvents'], 'TimeCode":')[1]

Condition

substring(outputs('Get_TimeCode'), 0, 1)

Legg igjen en kommentar

Din e-postadresse vil ikke bli publisert. Obligatoriske felt er merket med *