Skip to main content

Methods

The following core methods are available in all widget types.

MethodDescription
onSubscribe to an event.
offUnsubscribe a handler from an event.
hasCheck if a handler is registered for an event.
getWidgetGet current connected app widget object.
getContextGet current record or page context.
getCurrentUserGet logged-in user object.
getCurrentOrgGet current organization object.
isExportModeWhether the app is in export mode (e.g. PDF/image export).
isMobileWhether 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.

ParameterTypeDescription
namestringEvent name (e.g. "app.loaded", "app.destroyed")
handlerfunctionCallback to run when the event fires
contextanyOptional. 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().

ParameterTypeDescription
namestringEvent name
handlerfunctionThe 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.

ParameterTypeDescription
namestringEvent name
handlerfunctionHandler to check

Returns true if the handler is registered; false otherwise.

getWidget()#

Returns the current widget configuration object. Exposable fields:

FieldTypeDescription
idnumberWidget instance ID
connectedAppIdnumberConnected app ID
entityTypeEnumstringWidget 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")
widgetNamestringDisplay name of the widget
linkNamestringSlug/identifier (e.g. "twiliosettings")
resourcePathstringPath to app HTML (e.g. "/app/twilio-settings.html")
moduleIdnumberModule ID when in record context; -1 otherwise
orgIdnumberOrganization ID

Use entityTypeEnum to branch logic per widget type.

getContext()#

Returns context that varies by widget type:

Widget typeReturns
Web TabQuery params or empty
Record Summary TabCurrent 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 ButtonCurrent record object
PDF Template{ template, record, print, download }template: object with id, name, moduleId, templateSettingsJSON, templateTypeEnum, etc.; print/download: boolean
Dashboard WidgetDashboard object: { dashboardFilter, dashboardId, dashboardTabId, dashboardWidgets, id, linkName, name, orgId, sequence }
DialerEmpty
TopbarEmpty
Form - SidebarForm data object — record-like with field names and values (same as trigger('getFormData') result)
Form - BackgroundForm data object — record-like with field names and values (same as trigger('getFormData') result)
Related ListCurrent 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:

FieldTypeDescription
idnumberUser ID
namestringDisplay name
emailstringEmail address
userNamestringLogin username (often same as email)
orgIdnumberCurrent organization ID
timezonestringUser timezone (e.g. "Australia/Brisbane")
languagestringUser language (e.g. "en")
roleIdnumberRole ID
roleobjectRole details (id, description, isPrevileged, isSuperAdmin)
avatarNamestringInitials for avatar (e.g. "MV")
avatarUrlstring | nullAvatar image URL if set
activebooleanWhether user is active

getCurrentOrg()#

Returns the current organization object. Exposable fields:

FieldTypeDescription
idnumberOrganization ID
orgIdnumberSame as id
namestringOrganization display name
domainstringTenant identifier (e.g. "cbresandbox")
timezonestringOrg timezone (e.g. "Australia/Brisbane")
currencystringCurrency code (e.g. "AUD")
dateFormatstringDate format (e.g. "DD/MM/YYYY")
allowUserTimeZonebooleanWhether user timezone overrides org timezone
logoUrlstring | nullOrg 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}