spContextManager - Client
-
- UpdatedJan 30, 2025
- 3 minutes to read
- Yokohama
- API reference
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.
spContextManager - addContext(String key, Object context)
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.
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} . |
Type | Description |
---|---|
void |
Example
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.
spContextManager - getContext()
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.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Object | Each key and associated data object defined on the page. |
Example
spContextManager - getContextForKey(String key, Boolean returnPromise)
Returns the widget data associated with a key.
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:
|
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} . |
Example
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.
spContextManager - updateContextForKey(String key, Object context)
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.
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} . |
Type | Description |
---|---|
void |
Example
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.