---
sourceDocument: Australia API Reference
sourceDocumentLink: https://www.servicenow.com/docs/r/api-reference

 Release :

    - australia

ft:locale :

    - en-US

ft:publication_title :

    - Australia API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# spContextManager - Client

# spContextManager - Client {#ariaid-title1}

* Release version: Australia
* 
* Updated March 12, 2026
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

Makes data from a Service Portal widget available to other applications and services in a Service Portal page. For example, pass widget data to Agent Chat when it opens in a Service Portal page.

The spContextManager API is an AngularJS service that you can use in Service Portal widget client scripts.

Keys passed to this API are unique per page. For example, if the `'agent-chat'` key is already initialized by another widget on the page through the addContext() method, you must use the updateContextForKey() method to update the key's data. Available keys include:
agent-chat: Sends widget data to Agent Chat.

For more information about passing data to Agent Chat, see [Configure Agent Chat in Service
Portal](https://www.servicenow.com/docs/access?context=configure-va-in-sp&version=australia&pubname=australia-platform-user-interface&ft:locale=en-US).

## spContextManager - addContext(String key, Object context) {#ariaid-title2}

Initializes a key and adds widget data as the value. For example, add data to the
'agent-chat' key to make it available to Agent Chat.
Use this method the first time data is added to a specific key on a Service Portal page. If the key is
already used by another widget on the page, use the updateContextForKey()
method instead.
{#SPCM-addContext_S_O__table_dsz_dcz_qhb__entry__3}

| Name | Type | Description |
|-|-|-|
| key | String | Name of the key to send the data. Available keys includeagent-chat: Sends widget data to Agent Chat when it opens in a Service Portal page. |
| context | Object | Widget data in JSON format to send to the application or service specified in the key parameter. For example, `{'approval_count': 5}`. |
[Table 1. Parameters]

{#SPCM-addContext_S_O__table_dsz_dcz_qhb} {#SPCM-addContext_S_O__table_esz_dcz_qhb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 2. Returns]

{#SPCM-addContext_S_O__table_esz_dcz_qhb}  
Pass `approval_count` to Agent Chat. When a user initiates an Agent Chat conversation from the Service Portal homepage, the system appends `&sysparm_approval_count=5` to the Agent Chat `iframe` URL.

    function ($scope, spContextManager) {
        spContextManager.addContext('agent-chat', {
            'approval_count': 5       
        });
    };

## spContextManager - getContext() {#ariaid-title3}

Returns each key and associated data object defined by any widget on the
page.
Using this method may affect performance. Use this method to understand which keys are
initialized on the page and to get their current values. If you know which key you need to
access, use the getContextForKey() method instead.
{#SPCM-getContext__table_qgk_tdz_qhb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 3. Parameters]

{#SPCM-getContext__table_qgk_tdz_qhb} {#SPCM-getContext__table_rgk_tdz_qhb__entry__2}

| Type | Description |
|-|-|
| Object | Each key and associated data object defined on the page. |
[Table 4. Returns]

{#SPCM-getContext__table_rgk_tdz_qhb}  

    function ($scope, spContextManager) {
      spContextManager.getContext();
    } 

## spContextManager - getContextForKey(String key, Boolean returnPromise) {#ariaid-title4}

Returns the widget data associated with a key.
{#SPCM-getContextForKey_S_B__table_w2r_jcz_qhb__entry__3}

| Name | Type | Description |
|-|-|-|
| key | String | Name of the key to get context from. Available keys include: agent-chat: Sends widget data to Agent Chat. |
| returnPromise | Boolean | Flag that determines whether to return the data associated with a key as a promise or an object. Values include: * True: return the data as a promise. Use this option if another widget on the page uses the addContext() method to initialize the same key. Returning a promise prevents returning an undefined object when the key is not yet initialized. * False: returns an object containing the data associated with the key. {#SPCM-getContextForKey_S_B__ul_ccf_jvc_shb} |
[Table 5. Parameters]

{#SPCM-getContextForKey_S_B__table_w2r_jcz_qhb} {#SPCM-getContextForKey_S_B__table_x2r_jcz_qhb__entry__2}

| Type | Description |
|-|-|
| Promise | If returnPromise is true, returns a promise that is fulfilled when another widget on the page initializes the key. |
| Object | If returnPromise is false, returns an object containing the data associated with the key. For example, `{approval_count: 5}`. |
[Table 6. Returns]

{#SPCM-getContextForKey_S_B__table_x2r_jcz_qhb}  
Pass `approval_count` to Agent Chat. When a user initiates an Agent Chat conversation from the Service Portal homepage, the system appends `&sysparm_approval_count=5` to the Agent Chat `iframe` URL.

    function ($scope, spContextManager) {
      spContextManager.getContextForKey('agent-chat', true).then(function(context) {
        context = context || {};
        context.approval_count = 5; 
        spContextManager.updateContextForKey('agent-chat', context);
      });
    } 

## spContextManager - updateContextForKey(String key, Object context) {#ariaid-title5}

Sends data to an existing key. For example, if another widget on the page uses the
'agent-chat' key to pass data to the Agent Chat configuration, you must
update the context of the key rather than using the addContext()
method.
{#SPCM-updateContextForKey_S_O__table_mhr_lcz_qhb__entry__3}

| Name | Type | Description |
|-|-|-|
| key | String | Name of the key to send the data. Available keys includeagent-chat: Sends widget data to Agent Chat when it opens in a Service Portal page. |
| context | Object | Widget data in JSON format to send to the application or service specified in the key parameter. For example, `{'approval_count': 5}`. |
[Table 7. Parameters]

{#SPCM-updateContextForKey_S_O__table_mhr_lcz_qhb} {#SPCM-updateContextForKey_S_O__table_nhr_lcz_qhb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 8. Returns]

{#SPCM-updateContextForKey_S_O__table_nhr_lcz_qhb}  
Pass `approval_count` to Agent Chat. When a user initiates an Agent Chat conversation from the Service Portal homepage, the system appends `&sysparm_approval_count=5` to the Agent Chat `iframe` URL.

    function ($scope, spContextManager) {
      spContextManager.getContextForKey('agent-chat', true).then(function(context) {
        context = context || {};
        context.approval_count = 5; 
        spContextManager.updateContextForKey('agent-chat', context);
      });
    } 


