Skip to main content
Version: 8.1

system.perspective.sendMessage

This function is used in Python Scripting.

Description​

Send a message to a component message handler within the same session. This function cannot interact with Session Message Handlers configured in Session Events, even if the scope of session is specified.

The Scope Parameter​

It is important to be mindful of the scope parameter when calling this function. The scope argument corresponds to the listening scope of the component message handlers on any Perspective component.

It is possible to have multiple instances of a view open in a single page, thus invoking the function with a value of page for the scope parameter (or omitting the parameter) will invoke the message handlers on all valid message types. This advice is also applicable when the scope parameter value is passed as session, as all instances of the matching message type in the whole session will be called.

Syntax​

system.perspective.sendMessage(messageType, payload, [scope], [sessionId], [pageId])

Parameters​

TypeParameterDescription
StringmessageTypeThe message type that will be invoked. Message handlers configured within the project are listening for messages of a specific messageType.
Dictionary[String, String]payloadA Python dictionary representing any parameters that will be passed to the message handler.
StringscopeThe scope that the message should be delivered to. Valid values are "session", "page", or "view". If omitted, "page" will be used. [optional]
StringsessionIdIdentifier of the Session to target. If omitted, the current Session will be used automatically. When targeting a different session, then the pageId parameter must be included in the call. [optional]
StringpageIdIdentifier of the page to target. If omitted, the current page will be used. [optional]

Returns​

Nothing

Scope​

Gateway, Perspective Session

note

This function will only work in the Gateway scope if both sessionId and pageId are supplied to the call.

Code Examples​

Code Snippet

# Sends a message to all Message Handlers configured on the current view, indicating that a new item has been added to a list.
system.perspective.sendMessage("NewItem", payload = {"itemName":"banana","itemQuantity":6}, scope = "view")

Keywords​

system perspective sendMessage, perspective.sendMessage