1. Create a replacing object schema
- Open the Configuration section and select a custom package to add the schema.
-
Click Add → Replacing object on the section list toolbar.
-
Fill out the schema properties.
- Set Code to "Contact."
- Set Title to "Contact."
- Select "Contact" in the Parent object property.
-
Add an event to the schema.
- Open the Events node of the object structure.
-
Go to the Saving block → select the After record saved checkbox. Creatio names the event ContactSaved.
- Click Save on the Object Designer's toolbar.
-
Implement an event sub-process.
- Click Open process on the Object Designer's toolbar.
-
Click System actions in the element area of the Designer and drag theEvent sub-process element to the working area of the Process Designer.
- Set the Title property in the element setup area to "Contact Saved Sub-process."
-
Set up the event sub-process elements.
-
Set up the Message start event.
- Set Title to "After contact saved."
- Set Which message event should start the process? to "ContactSaved."
-
Add the Script task system action.
-
Click System actions in the element area of the Designer and drag the Script task system action to the working area of the sub-process.
- Name the Script task system action "Publish a message via WebSocket."
-
Add the code of the Script task system action.
- Click Save on the Process Designer's toolbar.
-
-
-
Set up the sequence flow. Click in the menu of the Message start event and connect the Message start event to the Publish a message via WebSocket system action.
View the event sub-process in the figure below.
- Click Save then Publish on the Process Designer's toolbar.
2. Implement message sending in Creatio
- Open the Configuration section and select a custom package to add the schema.
-
Click Add → Replacing view model on the section list toolbar.
-
Fill out the schema properties.
- Set Code to "ClientMessageBridge."
- Set Title to "ClientMessageBridge."
- Select "ClientMessageBridge" in the Parent object property.
-
Implement sending of the NewMessage broadcast message.
- In the messages property, bind the NewMessage broadcast message that can be published in Creatio.
-
Overload the following parent methods in the methods property:
- init(). Adds a message received via WebSocket to the schema's message configuration object.
- afterPublishMessage. Monitors the message sending.
View the source code of the replacing view model schema below.
- Click Save on the Designer's toolbar.
3. Implement subscription to the message
- Open the Configuration section and select a custom package to add the schema.
- Click Add → Replacing view model on the section list toolbar.
-
Fill out the schema properties.
- Set Code to "ContactPageV2."
- Set Title to "Display schema - Contact card."
- Select "ContactPageV2" in the Parent object property.
-
Implement subscription to the NewMessage broadcast message.
- In the messages property, bind the NewMessage broadcast message to subscribe.
- Overload the init() parent method in the methods property. The method subscribes to the NewMessage message. Implement the onNewMessage() handler method that handles the object received in the message and returns the result to the browser console.
View the source code of the replacing view model schema below.
- Click Save on the Designer's toolbar.
Outcome of the example
To view the outcome of the example:
- Clear the browser cache.
- Refresh the Contacts section page.
- Open the contact page. For example, Alexander Wilson.
- Open the Console tab in the browser console.
- Modify an arbitrary field.
- Save the contact.
As a result, the browser console will display the received and sent NewMessage messages.