samwoo Posted January 8 Share Posted January 8 Good afternoon, I would like to request for a supported API that will allow updating the Service Level Calendar (Working Time Calendar) in Hornbill. Application: Core Entity: SLC Name: slcUpdate Request Parameters: slcName <string> <required> timeZone <string> <required> workingTime <calendarWorkingTimeWeekType> exclusion <array> <calendarDayType> Response Parameters: status <string> exceptionName <string> exceptionSummary <string> Use case: To allow the automated updates of the Service Level Calendar via an external process. Example: Here is an example of a PowerShell script that can be set to run on Task Scheduler yearly, which currently works. Note - I've selected Python as the code formatting as there isn't a PowerShell option. # Initialize the last loaded time to a time far in the past if (-not $lastLoaded) { $lastLoaded = [DateTime]::MinValue } # Check if data is not loaded or more than 30 minutes have passed since last run if (-not $loaded -or ((Get-Date) - $lastLoaded).TotalMinutes -gt 30) { # Load the Hornbill API Config . '\\<SERVER NAME>\c$\<FOLDER>\Hornbill\Config\Hornbill_API_Config.ps1' # Load bank holidays from Gov UK JSON file $bankHolidays = (Invoke-WebRequest 'https://www.gov.uk/bank-holidays.json').content | ConvertFrom-Json # Update the last loaded time $lastLoaded = Get-Date $loaded = $true } # Extract the events for England and Wales, convert the date string to DateTime object, and sort by date $bankHoliday_govUK = $bankHolidays.'england-and-wales'.events | ForEach-Object { [PSCustomObject]@{ Title = $_.title Date = [DateTime]$_.date Note = $_.notes } } | Sort-Object Date # Define the Working Hours $startTime = '08:00:00' $endTime = '16:59:59' # Set the days of the week for the Service Desk Default Calendar # NOTE: # Days must be the first 3 letters. Add/Remove according to the open days/hours $daysOfWeek = @('mon', 'tue', 'wed', 'thu', 'fri') Add-HB-Param 'slcName' 'ServiceDeskDefaultCalendar' Add-HB-Param 'timeZone' 'GMT Standard Time' # Open the Working Timne element Open-HB-Element 'workingTime' # Iterate through each day of the week foreach ($day in $daysOfWeek) { # Open the element associated with that day of the week Open-HB-Element $day # Add the Start and End times Add-HB-Param 'start' "$startTime" Add-HB-Param 'end' "$endTime" Close-HB-Element $day } Close-HB-Element 'workingTime' # Iterate through each bank holiday from GOV UK foreach ($holiday in $bankHoliday_govUK) { # Skip standard holidays if ($holiday.Title -like '*Christmas*' -or ` $holiday.Title -like '*Boxing*' -or ` $holiday.Title -like '*New Year*' -and (-not $holiday.Note) ) { # Skip the standard holiday dates if there is no note on it continue } # Open the "exclusion" element Open-HB-Element 'exclusion' # Add the day, month, year, and comment parameters Add-HB-Param 'day' $holiday.Date.Day Add-HB-Param 'month' $holiday.Date.Month Add-HB-Param 'year' $holiday.Date.Year # If the holiday has a note (ie. Substitute Day) if ($holiday.Note) { # Append the Note to the end of the comment Add-HB-Param 'comment' "$($holiday.Title) ($($holiday.Note))" } else { # Just use the comment Add-HB-Param 'comment' $holiday.Title } # Close the "exclusion" element Close-HB-Element 'exclusion' } Invoke-HB-XMLMC 'time' 'slcUpdate' Clear-HB-Params Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now