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)
{"title":"Updated Resource(s) Available - Refresh Resource List"}

{
"messageDetail":"\"[svmx_job](WO-00010406)\" needs immediate dispatch.",
"title":"High-Priority Job Created"
}

{
"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."
}

{
"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."
}

|
|
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."
]
}

// 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.
|


