Examples of Groovy Scripts for Sending Notifications to Slack
Here are some examples of groovy scripts for sending notifications from Fusion Service to Slack:
Trigger Example: SR Critical Check Box Change
Use the following code to trigger a notification to be sent to Slack when the Critical check box on the service request (SR) is updated:
Note: All the steps to set the HashMap in these examples
are required to send notifications to Slack. Currently, Slack notifications
don't use the Notification Preferences Manager. So it's necessary
to pass the HashMap to the sendNotification method.
// TRIGGER TYPE: AFTER CHANGES POSTED TO DATABASE
// Notify #support channel in OraSvc workspace when the Critical check box in an SR is selected or deselected
int indexOfCF = adf.oldValue.getAttributeIndexOf('CriticalFlag')
def oldValue = adf.oldValue.getAttribute(indexOfCF,oracle.jbo.server.EntityImpl.TRANS_ORIGINAL_VERSION)
def newValue = getAttribute('CriticalFlag')
if (oldValue != newValue) {
println("Triggering notification...") // For debugging purpose only
try {
def map = new HashMap()
map.put("Channels",["ORA_SVC_SLACK"])
map.put("MessageText","Test Message for a change to the Critical check box on the SR")
map.put("ChannelAccountName", "A1B2C3D4F5") // This is a very important step to send notifications to Slack. Pass the Account Name field for the Slack channel that you created
map.put("SlackChannels", ["@kanyuev", "#general", ...]) // This is also an important step. You can provide one or more Slack channels or users here
adf.util.sendNotification(adf, map)
println("Success.") // For debugging purpose only
} catch (e) {
throw new oracle.jbo.ValidationException('Failure: ' + e.getMessage())
}
}
Trigger Example: SR Created
Use the following code to trigger a notification to be sent to Slack when an SR is created:
// TRIGGER TYPE: BEFORE INSERT TO DATABASE
// Notify #support channel in OraSvc workspace when an SR is created
try {
def map = new HashMap()
map.put("Channels",["ORA_SVC_SLACK"])
map.put("MessageText","An SR is created")
map.put("ChannelAccountName", "A1B2C3D4F5") // This is a very important step to send notifications to Slack. Pass the Account Name field for the Slack channel that you created
map.put("SlackChannels", ["@kanyuev", "#general", ...]) // This is also an important step. You can provide one or more Slack channels or users here
adf.util.sendNotification(adf, map)
} catch (e) {
throw new oracle.jbo.ValidationException('Failure: ' + e.getMessage())
}