Methods
The following core methods are available in all widget types.
| Method | Description |
|---|---|
| on | Subscribe to an event. |
| off | Unsubscribe a handler from an event. |
| has | Check if a handler is registered for an event. |
| getWidget | Get current connected app widget object. |
| getContext | Get current record or page context. |
| getCurrentUser | Get logged-in user object. |
| getCurrentOrg | Get current organization object. |
| isExportMode | Whether the app is in export mode (e.g. PDF/image export). |
| isMobile | Whether the app is running on mobile. |
Event listener methods#
on(name, handler, context?)#
Subscribe to an event. Use for app.loaded, app.destroyed, and widget-specific events.
| Parameter | Type | Description |
|---|---|---|
| name | string | Event name (e.g. "app.loaded", "app.destroyed") |
| handler | function | Callback to run when the event fires |
| context | any | Optional. If provided, handler is bound to this value. |
window.facilioApp.on('app.loaded', (data) => { console.log('SDK ready', data);});
// With context (handler bound to Vue instance)window.facilioApp.on('app.destroyed', this.cleanup, this);off(name, handler)#
Unsubscribe a handler from an event. Pass the same function reference used in on().
| Parameter | Type | Description |
|---|---|---|
| name | string | Event name |
| handler | function | The handler to remove (must be the same reference) |
Returns the handler if removed; false if the event had no handlers.
const handler = (data) => console.log('loaded', data);window.facilioApp.on('app.loaded', handler);// later:window.facilioApp.off('app.loaded', handler);has(name, handler)#
Check if a handler is registered for an event.
| Parameter | Type | Description |
|---|---|---|
| name | string | Event name |
| handler | function | Handler to check |
Returns true if the handler is registered; false otherwise.
getWidget()#
Returns the current widget configuration object. Exposable fields:
| Field | Type | Description |
|---|---|---|
| id | number | Widget instance ID |
| connectedAppId | number | Connected app ID |
| entityTypeEnum | string | Widget type (e.g. "WEB_TAB", "SUMMARY_PAGE", "CUSTOM_BUTTON", "EDIT_RECORD_PAGE", "CREATE_RECORD_PAGE", "DASHBOARD_WIDGET", "DIALER", "TOPBAR", "FORM_SIDEBAR", "FORM_BACKGROUND", "RELATED_LIST", "PDF_TEMPLATE") |
| widgetName | string | Display name of the widget |
| linkName | string | Slug/identifier (e.g. "twiliosettings") |
| resourcePath | string | Path to app HTML (e.g. "/app/twilio-settings.html") |
| moduleId | number | Module ID when in record context; -1 otherwise |
| orgId | number | Organization ID |
Use entityTypeEnum to branch logic per widget type.
getContext()#
Returns context that varies by widget type:
| Widget type | Returns |
|---|---|
| Web Tab | Query params or empty |
| Record Summary Tab | Current record object |
| Create Record Page | { record: {}, query: {...} } — record is empty object; query has URL params if any |
| Edit Record Page | { record: recordObject, query: {...} } — current edit record; query has URL params if any |
| Custom Button | Current record object |
| PDF Template | { template, record, print, download } — template: object with id, name, moduleId, templateSettingsJSON, templateTypeEnum, etc.; print/download: boolean |
| Dashboard Widget | Dashboard object: { dashboardFilter, dashboardId, dashboardTabId, dashboardWidgets, id, linkName, name, orgId, sequence } |
| Dialer | Empty |
| Topbar | Empty |
| Form - Sidebar | Form data object — record-like with field names and values (same as trigger('getFormData') result) |
| Form - Background | Form data object — record-like with field names and values (same as trigger('getFormData') result) |
| Related List | Current record object (parent record) |
For Record Summary Tab, Custom Button, and Related List, the context is the record object directly — use let record = window.facilioApp.getContext(), not ctx.record. For Create/Edit Record and PDF Template, the context is an object with a record property.
getCurrentUser()#
Returns the logged-in user object. Key fields:
| Field | Type | Description |
|---|---|---|
| id | number | User ID |
| name | string | Display name |
| string | Email address | |
| userName | string | Login username (often same as email) |
| orgId | number | Current organization ID |
| timezone | string | User timezone (e.g. "Australia/Brisbane") |
| language | string | User language (e.g. "en") |
| roleId | number | Role ID |
| role | object | Role details (id, description, isPrevileged, isSuperAdmin) |
| avatarName | string | Initials for avatar (e.g. "MV") |
| avatarUrl | string | null | Avatar image URL if set |
| active | boolean | Whether user is active |
getCurrentOrg()#
Returns the current organization object. Exposable fields:
| Field | Type | Description |
|---|---|---|
| id | number | Organization ID |
| orgId | number | Same as id |
| name | string | Organization display name |
| domain | string | Tenant identifier (e.g. "cbresandbox") |
| timezone | string | Org timezone (e.g. "Australia/Brisbane") |
| currency | string | Currency code (e.g. "AUD") |
| dateFormat | string | Date format (e.g. "DD/MM/YYYY") |
| allowUserTimeZone | boolean | Whether user timezone overrides org timezone |
| logoUrl | string | null | Org logo URL if set |
isExportMode()#
Returns true when the app is in export mode (e.g. when exporting the widget as PDF or image via Facilio Script). Use this to adjust layout or hide interactive elements during export.
isMobile()#
Returns true when the app is running on mobile (webview). Use this to branch UI or behavior for mobile vs web.
Example
let widget = window.facilioApp.getWidget();if (widget.entityTypeEnum === "SUMMARY_PAGE") { // do this}
// For Record Summary, Custom Button, Related List: context is the record directlylet currentRecord = window.facilioApp.getContext();console.log("Record Name: " + currentRecord.name);
let currentUser = window.facilioApp.getCurrentUser();console.log("Current User Email: " + currentUser.email);console.log("Timezone: " + currentUser.timezone);
let currentOrg = window.facilioApp.getCurrentOrg();console.log("Current Org Domain: " + currentOrg.domain);
if (window.facilioApp.isExportMode()) { // simplify layout for PDF/image export}if (window.facilioApp.isMobile()) { // mobile-specific UI or behavior}