Service Add-ins are background integrations that run within the MyGeotab platform using WebWorkers.

Below is an example of a Service Add-In that runs in the background using a WebWorker. Service Add-Ins have no user interface and operate behind the scenes to perform tasks such as data processing, API calls, or event monitoring without impacting the main MyGeotab interface.

Installation

Service Add-ins are background integrations that run within the MyGeotab platform using WebWorkers.

Below is an example of a Service Add-In that runs in the background using a WebWorker. Service Add-Ins have no user interface and operate behind the scenes to perform tasks such as data processing, API calls, or event monitoring without impacting the main MyGeotab interface.

Service Add-Ins are installed by uploading an Add-In Configuration file into MyGeotab. Click on System Settings > Add-Ins > New Add-In, and upload the Add-In Configuration file. The following is an example of a Service Add-In's Configuration file:

The main properties of the Configuration file are as follows:

  1. serviceName - This defines the name of the Service Add-in.
  2. serviceSrc - The JavaScript file reference for the Service Add-in. This should be an externally hosted file that will be run in WebWorker environment.

The main function example:

This function has one argument:

  1. service - Available services to be called from the WebWorker.

The Add-in function will be called when a user opens MyGeotab web page. Service Add-Ins run in the background without a user interface, being able to perform tasks such as data processing, API calls, or event monitoring.

Service Add-In services

Notifications service

Service for showing notifications to the user

Methods

Service methodsDescription
show (options: INotificationOptions): INotificationShows new notification

Interface INotificationOptions

PropertyTypeDescription
titlestringNotification title
textstringNotification text
type"info" | "warning" | "error" | "success"Notification type
durationnumberNotification duration in seconds
buttonsINotificationButton[]Array of notification buttons. Maximum of 2 buttons are supported

Interface INotificationButton

PropertyTypeDescription
titlestringButton title
hideOnClickbooleanWhether to hide the notification when the button is clicked
click() => voidClick handler for the button

Interface INotification

New notification object

MethodDescription
hide (): voidRemoves current notification

Page service

Service for getting/setting page state and moving between MyGeotab page

Methods

Service methodsDescription
getCurrentPageName (): Promise<string>Gets current page name
set (key: string, value: string): Promise<boolean>Sets new key/value pair to page state
get (): Promise<object>Gets page state
go (page: string, state?: object): Promise<boolean>Changes current page
hasAccessToPage (page: string): Promise<boolean>Checks whether current user has access to MyGeotab page
getFilterState (): Promise<IGroupFilterId[]>Gets current company filter state
getFilterValue(): Promise<IFilterState>Gets advanced filter state
attach (eventName: string, eventHandler: (serviceData: any) => void): voidAttaches event handler to service
detach (eventName: string, eventHandler?: (serviceData: any) => void): voidDetaches event handler to service

Events

Event nameEvent objectDescription
activeChange
event: (IActiveStateEvent) - Active state event object
Event is fired when user switches between browser tab
pageChange
pageName: (string) - New page name
Event is fired when the page is changed
stateChange
state: (object) - Updated page state
Event is fired when the state of the page is changed
filterChange
groups: (IGroupFilterId[]) - Updated array of filter groups
Event is fired when the company filter groups is changed
changeFilterValue
groups: (IFilterState[]) - Updated array of filter groups
Event is fired when the company filter groups is changed

Interface IGroupFilterId

Group id object that is selected by user in company filter

PropertyType
idstring

Interface IFilterState

Group state object that is selected by user in company filter

PropertyType
relation"And" | "Or"
itemsIFilterState | IGroupFilterId

Interface IActiveStateEvent

PropertyType
activeboolean

Api service

Service for requesting data from Geotab server

Methods

Service methodsDescription
call (method: string, params: object): Promise<any[]>Sends single request to Geotab server
multiCall (calls: TApiCall[]): Promise<any[][]>Sends multiple requests to Geotab server in one batch
getSession (): Promise<ISessionInfo>Gets current user session information

Interface ISessionInfo

Current user session information

PropertyType
databasestring
userNamestring
sessionIdstring
domainstring

Type TApiCall

[string, object]

Tuple for calling server methods where first element is method name and second is an object with parameters.

localStorage service

Service to request information stored in browser LocalStorage

Methods

Service methodsDescription
set (key: string, value: string): Promise<boolean>Sets key-value pairs to browser localStorage with key
remove (key: string): Promise<boolean>Removes value from browser localStorage by key
get (key: string): Promise<string>Gets value from browser localStorage by key
Example Add-Ins

The example of service add-in that sends notification to a user when the add-in is loaded. There are two buttons in the notification, "Report" and "Cancel". The "Report" button logs a message to the console without hiding the notification, while the "Cancel" button hides the notification and also logs a message to the console.