---
sourceDocument: Brazil Customer Service Management
sourceDocumentLink: https://www.servicenow.com/docs/r/customer-service-management

 Release :

    - brazil

ft:locale :

    - en-US

ft:publication_title :

    - Brazil Customer Service Management

ft:clusterId :

    - csm

bundleId :

    - csm

workflow :

    - Customer and Industry


---

# Functions available in Web Embeddables global and component code

# Functions available in Web Embeddables global and component code {#ariaid-title1}

Release version: Brazil  
Updated September 10, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 minutes to read
Summarize  
![AI sparkle icon](https://servicenow.com/docs/portal-asset/ai-sparkle-icon) Summarized using AI  
This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.  

## Summary of Functions available in Web Embeddables global and component code

This guide explains how to use the ServiceNow Embeddables API to integrate ServiceNow components into external websites.
It outlines the global and component-level functions available in the embed script for initializing, authenticating, managing components, and handling events efficiently.
This functionality enables ServiceNow customers to seamlessly embed ServiceNow UI components with support for authentication, theming, localization, session management, and performance optimization.
Show full answer Show less  

## Global Code Functions

* **init()**: Initializes the embeddables framework with configuration settings such as the ServiceNow instance URL, theme, locale, session timeout interception, and optional component pre-caching. This function must be called first before any other embeddables functions. It establishes connections, loads resources, updates user language preferences if provided, and improves performance by caching specified components.
* **login()** : Authenticates the user with ServiceNow using the authentication callback provided during init(). On successful login, it dispatches a **SNEMBEDDABLESLOGINSUCCESS** event. Prerequisites include having called init() with a valid authCallback function returning a valid token.
* **logout()** : Logs out the user from the ServiceNow session and dispatches a **SNEMBEDDABLESLOGOUTSUCCESS** event. Requires prior successful init() and that the user is logged in.

## Component Code Functions

* **getEmbeddables(components)**: Loads and initializes specified embeddable components by their tag names. This allows you to dynamically embed multiple ServiceNow components in your external site.
* **setProperties(componentElement, properties)**: Sets properties on a given embeddable component instance, enabling customization such as specifying table names, sysids, and context-related identifiers to tailor component behavior.
* **setEvents(componentElement, eventHandlers)**: Attaches event listeners to embeddable components to handle lifecycle events like readiness and errors. This allows monitoring and responding to component states and errors programmatically.

## Key Considerations for Implementation

* Always call **init()** first to establish the embeddables framework and configurations.
* Use the **authCallback** function in init() to supply valid authentication tokens for login.
* Leverage **cacheComponents** in init() to pre-cache frequently used components and improve load performance.
* Attach event handlers to components using **setEvents()** to monitor component lifecycle events and handle errors effectively.
* Ensure logout is handled appropriately to maintain session security.  
Use these functions to initialize, authenticate, manage components, and handle events when you embed ServiceNow components on external websites.

## Global code {#we-global-code-functions__section_rmr_jvl_bgc}

The ServiceNow Embeddables API integrates ServiceNow components into your external websites.  
The embed script includes the following methods as part of the global code. The following details help you understand how they work.

Init method
:
    * Purpose: Initializes the embeddables framework with configuration settings.
    * Usage pattern:

          await init({
          	theme: 'fad87d2ca304121029a4d1aed31e610f', //sys_id of theme,
          	baseURL: 'https://demo.servicenow.com',
          	authCallback: getTokenCallBack, // Authentication callback function 
                 locale: 'ja', // Language/locale for components
                 interceptSessionTimeout: true, // Handle session timeouts (default: true)
          	// cacheComponents: [ //Pre-cache component for performance  "sn-embedx-case-form", "sn-embedx-case-list", "sn-embedx-case-view" ]
          });

    * Parameters:
      * `authCallback` (Function): Returns authentication token for the current user.
      * `baseURL` (String): Base URL of the ServiceNow instance.
      * `locale` (String, optional): Language/locale setting (for example, 'en', 'es') that updates the user's language preference in ServiceNow for authenticated user.
      * `theme` (String): The sys_id of theme to apply.
      * `interceptSessionTimeout` (Boolean, optional): Enable session timeout handling. By default, it is set to <kbd class="ph userinput">true</kbd>.
      * `cacheComponents` (Array, optional): List of component tag names to pre-cache.
      {#we-global-code-functions__ul_ilk_2cm_bgc}
    * Key behaviors:
      * Must be called before any other embeddables functions.
      * Loads necessary resources and establishes a connection.
      * Optionally sets up interceptors for session management.
      * Updates the user's language preference for the authenticated user if locale is provided.
      * Pre-caches specified components for improved performance.
      {#we-global-code-functions__ul_kll_rcm_bgc}
    {#we-global-code-functions__ul_ibr_wxl_bgc}

login()
:
    * Purpose: Authenticates the user with the ServiceNow instance.
    * Usage Pattern:

          await login();

    * Key behaviors:
      * Calls the authCallback function provided during initialization.
      * Authenticates with the returned token - Dispatches SN_EMBEDDABLES_LOGIN_SUCCESS event on success.
      {#we-global-code-functions__ul_u5t_4dm_bgc}
    * Prerequisites: `init()` must be called first with a valid authCallback - authCallback function must return a valid authentication token.
    {#we-global-code-functions__ul_s2s_fdm_bgc}

logout()
:
    * Purpose: Logs out the user from ServiceNow session.
    * Usage pattern:

          await logout();

    * Key behaviors: Dispatches SN_EMBEDDABLES_LOGOUT_SUCCESS event on success.
    * Prerequisite: `init()` must be called first with valid baseURL - User must be logged in.
    {#we-global-code-functions__ul_n15_vdm_bgc}

## Component code {#we-global-code-functions__section_jyc_k2m_bgc}

The embed script includes the following methods as part of the component code. The following details help you understand how they work.

getEmbeddables
:
    * Purpose: Loads and initializes specified embeddable components.
    * Usage pattern:

          // Load components by providing array of component tag names
          getEmbeddables(["sn-embedx-case-view", "sn-embedx-case-form"]);

    * Parameters: `components` (Array): Array of component tag names to load
    {#we-global-code-functions__ul_il2_n2m_bgc}

setProperties(componentElement, properties)
:
    * Purpose: Sets properties on embeddable component instances.
    * Usage pattern:

          const caseViewComponent = document.querySelector('sn-embedx-case-view');
          setProperties(snEmbedxCaseView,{
          		table:sn_customerservice_case,
          		sysId:221a69cd3b411300b5c42479b3efc480,
          		playbookExperience:playbookExperience,
          		selectedPlaybookContextId:85d9f349ff766210e9d3ffffffffffce,
          		selectedStageContextId:9da56770ff7a2210e9d3ffffffffffd9,
          		selectedActivityContextId:5d8bf1805d8bf8205d8b54d05d8be070 });

    * Parameters: `componentElm` (HTMLElement): The component DOM element - properties (Object): Key-value pairs of properties to set.
    {#we-global-code-functions__ul_lx3_dfm_bgc}

setEvents (componentElement, eventHandlers)
:
    * Purpose: Attaches event listeners to embeddable components.
    * Usage pattern:

          const caseViewComponent = document.querySelector('sn-embedx-case-view');
          const eventHandlers = {'
          'SN_EMBEDX_CASE_VIEW#COMPONENT_READY': (e) => { 
          console.log('Component is ready and usable'); }, 
          'SN_EMBEDX_CASE_VIEW#COMPONENT_ERROR': (e) => { const 
          { errorMessage, errorType } = e.detail.payload;
          console.log('Component error:', errorMessage, errorType); },
          };
          setEvents(caseViewComponent, eventHandlers); 

    * Parameters: `componentElm` (HTML Element): The component DOM element - eventHandlers (Object): Key-value pairs where keys are event names and values are handler functions.
    {#we-global-code-functions__ul_wgy_3gm_bgc}

## Key considerations {#we-global-code-functions__section_xmz_zyz_bgc}

Here are some key considerations to help you implement this effectively:

* Ensure to call init() first. It sets up the foundation for all other functions.
* Use event handlers for the component life-cycle. It also monitor component readiness and errors.
* Cache frequently used components. Use cacheComponents in init() for better performance.
* Implement
{#we-global-code-functions__ul_kq1_2zz_bgc}

