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 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:
The main function example:
This function has one argument:
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 for showing notifications to the user
| Service methods | Description |
|---|---|
| show (options: INotificationOptions): INotification | Shows new notification |
| Property | Type | Description |
|---|---|---|
| title | string | Notification title |
| text | string | Notification text |
| type | "info" | "warning" | "error" | "success" | Notification type |
| duration | number | Notification duration in seconds |
| buttons | INotificationButton[] | Array of notification buttons. Maximum of 2 buttons are supported |
| Property | Type | Description |
|---|---|---|
| title | string | Button title |
| hideOnClick | boolean | Whether to hide the notification when the button is clicked |
| click | () => void | Click handler for the button |
New notification object
| Method | Description |
|---|---|
| hide (): void | Removes current notification |
Service for getting/setting page state and moving between MyGeotab page
| Service methods | Description |
|---|---|
| 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): void | Attaches event handler to service |
| detach (eventName: string, eventHandler?: (serviceData: any) => void): void | Detaches event handler to service |
| Event name | Event object | Description |
|---|---|---|
| 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 |
Group id object that is selected by user in company filter
| Property | Type |
|---|---|
| id | string |
Group state object that is selected by user in company filter
| Property | Type |
|---|---|
| relation | "And" | "Or" |
| items | IFilterState | IGroupFilterId |
| Property | Type |
|---|---|
| active | boolean |
Service for requesting data from Geotab server
| Service methods | Description |
|---|---|
| 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 |
Current user session information
| Property | Type |
|---|---|
| database | string |
| userName | string |
| sessionId | string |
| domain | string |
[string, object]Tuple for calling server methods where first element is method name and second is an object with parameters.
Service to request information stored in browser LocalStorage
| Service methods | Description |
|---|---|
| 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 |
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.