Creating Message Center Notifications With Custom Operations
You can create custom Message Center notifications by using the standard Create REST API to implement custom operations that create Message records. For example, you might want to create a validation warning operation for cases where dispatchers create or update Appointments that overlap with other Events or Appointments and configure a Message Center notification. After you create these custom notifications, only the associated record owners can view them in Message Center. By default, pop-up notifications are disabled, and you can enable them if needed.
To create Message Center notifications with custom operations:
1. Implement the following Groovy code to create a custom operation:
import com.servicemax.core.Database
import com.servicemax.core.MaxObject
import com.servicemax.core.Record
import com.servicemax.core.Max
import com.fasterxml.jackson.databind.ObjectMapper

MaxObject message = Record.newRecord('svmx_message')
// Set required fields: svmx_name, svmx_message_type, svmx_message, io_owner
message.svmx_name = 'Custom Notification'
// Set the type as Notification
message.svmx_message_type = 'Notification'
def objectMapper = new ObjectMapper()
message.svmx_message = objectMapper.writeValueAsString([title: 'Custom Notification', messageDetail: '[svmx_job](WO-00001) is Created.'])
// The notification will only shows on the owner's Message Center
message.io_owner = Max.effectiveUserUUID()
// Specifies whether to display a pop-up notification for the owner when the message is received.
message.svmx_display_toast_alert = true
// Define the pop-up notification level: Information, Warning, Error
message.svmx_popup_notification_type = 'Information'

Database.insert(message)
2. Set properties for the notification formats you want to use, as follows:
Title Only: Set the title property for the Message field​.
{"title":"Updated Resource(s) Available - Refresh Resource List"}
Title With Details: Set the title and messageDetail properties for the Message field.
{
"messageDetail":"\"[svmx_job](WO-00010406)\" needs immediate dispatch.",
"title":"High-Priority Job Created"
}
Include Related Records: Set the title and records properties for the Message field, and include the id, name and object properties to make records clickable.
{
"messageDetailList":[],"records":
[
{
"id":"38314401-1d89-421f-bb22-5ef2ce259069",
"name":"Alan Carr",
"object":"svmx_resource"
},
{
"id":"3924457f-ca67-4298-b2d8-b5991bd3ad54",
"name":"Big Truck",
"object":"svmx_resource"
},
{
"id":"2ce23700-42e2-4024-a4a3-a5dff6b06310",
"name":"Bill Walter",
"object":"svmx_resource"
},
{
"id":"f6278f4f-b81d-4abe-83ed-0d9999e05136",
"name":"Black Trunk",
"object":"svmx_resource"
}
],
"title":"Some resource(s)/crew(s) cannot be displayed on map because location data is missing."
}
Detailed List: Set the title and messageDetailList properties for the Message field.
{
"messageDetailList":
[
"Data validation error (Error code: 512). The value of Field \"workingHours\" cannot be greater than 1 day for Resource \"Samuel Coogan\".",
"Data validation error (Error code: 512). The value of Field \"workingHours\" cannot be greater than 1 day for Resource \"Lisa Mizel\".",
"Data validation error (Error code: 517). Fields \"geoLocation\" and \"Address\" cannot both be empty for Job WO-00010288."
],
"records":
[
],
"title":"Error occurred while trying to initiate Propose Schedule."
}
Context With Note: Set the context property for the Message field.
* 
This property is valid only for Message Cards, and is ignored by pop-up notifications.
{
"context":
[
"Job: [svmx_job](WO-00011243)",
"Related Resource List: All Resources"
],
"title":"Error occurred while trying to initiate Schedule Proposals.",
"messageDetailList":
[
"Appointment Proposals ended without result (Error code: 7). No appointment times meet job requirements or other hard constraints. Could not schedule Job(s): [svmx_job](WO-00011243)",
"Could not schedule Job(s): WO-00011243 (Error code: 112). Scheduling job would have exceeded the maximum driving distance."
]
}
3. To enable pop-up notifications, do one of the following:
If the notification is configured with a Message Request, navigate to the relevant record and select the Display Pop-Up Notification check box.
If the notification is configured with a custom operation, set message.svmx_display_toast_alert to true.
// Specifies whether to display a pop-up notification for the owner when the message is received.
message.svmx_display_toast_alert = true
def bottomRecords = [[name: 'WO-006', object: 'svmx_job'], [name: 'WO-007', object: 'svmx_job'], [name: '[WO-018] Appointment', object: 'svmx_appointment', id: '4b1b205f-e9f4-4482-9028-8677012e403c']]
message.svmx_message = objectMapper.writeValueAsString([title: 'Custom Notification title', messageDetail: 'Already dispatched to [svmx_resource](Andrea Boulter | 2ae2ecdb-8f1b-43c0-90cb-1b78f61a762e).', messageDetailList: ["[svmx_job](WO-002) is Created.", "[svmx_job](WO-003) is Created."], records: bottomRecords])
message.svmx_popup_notification_type = 'Information'
* 
You can set message.svmx_popup_notification_type to Information, Warning, or Error. If no value is set in this field, the value defaults to Warning. For more information, see Configuring Browser Notifications in Max for Administrators.
Information: Renders with a blue block on the left side. This notification auto-dismisses after 7 seconds.
Warning: Appears with an orange block on the left. This notification does not auto-dismiss.
Error: Appears with a yellow block on the left side. This notification does not auto-dismiss.
For more information:
Was this helpful?