Sample Groovy Scripts for Notifications
Use Groovy scripts to define the start of notifications. Here's sample code to generate notifications to the recipients specified in the Notification Preferences page for sales objects. You can modify the scripts to fit your requirements.
Scripts for Standard Objects
Here are sample scripts for standard sales objects:
Object |
Scenario |
Create and Assign Scripts |
---|---|---|
Accounts |
Push notification received |
Account Create // Send notification to Owner
when Account is created // Use trigger type BEFORE INSERT TO DATABASE def
map = new HashMap(); // Specify one or more channels
map.put("Channels",["ORA_SVC_BELL"]); // Specify default MessageText def
messageText = "Account created with name: " + OrganizationName;
map.put("MessageText", messageText); // The following can be used to pass
a Long PartyId map.put("RecipientPartyId", OwnerPartyId);
adf.util.sendNotification(adf, map) |
Accounts |
Drill down to details page |
Account Assign // Send notification to Owner
when Account is assigned to them // Use trigger type BEFORE UPDATE TO
DATABASE if (isAttributeChanged('OwnerPartyId')) { try { def
map = new HashMap(); def messageText = "This Account has been
assigned to you" def recipientPartyId = OwnerPartyId //
Specify one or more channels
map.put("Channels",["ORA_SVC_BELL"]); // Specify default
MessageText map.put("MessageText", messageText); // The
following can be used to pass a Long PartyId
map.put("RecipientPartyId", recipientPartyId); if
(recipientPartyId) { adf.util.sendNotification(adf, map)
} else { println("No Owner associated with this Account")
} } catch (e) { throw new
oracle.jbo.ValidationException('Failure: ' + e.getMessage()) }
} |
Contacts |
Push notification received |
Contact Create // Send notification to Owner
when Contact is created // Use trigger type BEFORE INSERT TO DATABASE def
map = new HashMap(); // Specify one or more channels map.put("Channels",[
"ORA_SVC_BELL"]); // Specify default MessageText def messageText =
"Contact created with name: " + PersonName; map.put("MessageText",
messageText); // The following can be used to pass a Long PartyId
map.put("RecipientPartyId", OwnerPartyId); adf.util.sendNotification(adf,
map) |
Contacts |
Drill down to details page |
Contact Assign // Send notification to Owner
when Contact is assigned to them // Use trigger type BEFORE UPDATE TO
DATABASE if (isAttributeChanged('OwnerPartyId')) { try { def
map = new HashMap(); def messageText = "This Contact has been
assigned to you" def recipientPartyId = OwnerPartyId //
Specify one or more channels map.put("Channels",[
"ORA_SVC_BELL"]); // Specify default MessageText
map.put("MessageText", messageText); // The following can be used
to pass a Long PartyId map.put("RecipientPartyId",
recipientPartyId); if (recipientPartyId) {
adf.util.sendNotification(adf, map) } else {
println("No Owner associated with this Contact") } } catch
(e) { throw new oracle.jbo.ValidationException('Failure: ' +
e.getMessage()) } } |
Leads |
Push notification received |
Lead Create // Send notification to Owner when
Lead is created // Use trigger type BEFORE INSERT TO DATABASE def map =
new HashMap(); //give lead object API name def objectCode = 'MklLeadVO'
map.put("ObjectCode", objectCode) // Specify one or more channels
map.put("Channels",["ORA_SVC_BELL"]); // Specify default MessageText def
messageText = "Lead created with name: " + Name; map.put("MessageText",
messageText); // The following can be used to pass a Long PartyId
map.put("RecipientPartyId", OwnerId); adf.util.sendNotification(adf,
map); |
Leads |
Drill down to details page |
Lead Assign Lead Assign // Send notification
to Owner when Lead is assigned to them // Use trigger type BEFORE UPDATE
TO DATABASE if (isAttributeChanged('OwnerId')) { try { def
map = new HashMap(); def messageText = "This Lead has been
assigned to you" def recipientPartyId = OwnerId //
Specify one or more channels
map.put("Channels",["ORA_SVC_BELL"]); // Specify default
MessageText map.put("MessageText", messageText); // The
following can be used to pass a Long PartyId
map.put("RecipientPartyId", recipientPartyId); if
(recipientPartyId) { adf.util.sendNotification(adf, map)
} else { println("No Owner associated with this Lead")
} } catch (e) { throw new
oracle.jbo.ValidationException('Failure: ' + e.getMessage()) }
} |
Opportunities |
Push notification received |
Opportunity Create // Send notification to
Owner when Opportunity is created // Use trigger type BEFORE INSERT TO
DATABASE def map = new HashMap(); // Specify one or more channels
map.put("Channels",["ORA_SVC_BELL"]); // Specify default MessageText def
messageText = "Opportunity created with name: " + Name;
map.put("MessageText", messageText); // The following can be used to pass
a Long PartyId map.put("RecipientPartyId", OwnerResourcePartyId);
adf.util.sendNotification(adf, map) |
Opportunities |
Drill down to details page |
Opportunity Assign // Send notification to
Owner when Opportunity is assigned to them // Use trigger type BEFORE
UPDATE TO DATABASE if (isAttributeChanged('OwnerResourcePartyId')) {
try { def map = new HashMap(); def messageText = "This
Opportunity has been assigned to you" def recipientPartyId =
OwnerResourcePartyId // Specify one or more channels
map.put("Channels",[ "ORA_SVC_BELL"]); // Specify default
MessageText map.put("MessageText", messageText); // The
following can be used to pass a Long PartyId
map.put("RecipientPartyId", recipientPartyId); if
(recipientPartyId) { adf.util.sendNotification(adf, map)
} else { println("No Owner associated with this Opportunity")
} } catch (e) { throw new
oracle.jbo.ValidationException('Failure: ' + e.getMessage()) } }
|
// Specify one or more channels map.put("Channels",["ORA_SVC_BELL",
"ORA_SVC_OMNI","ORA_SVC_MOBILE"]););
-
ORA_SVC_BELL: Notifications icon in the global header
-
ORA_SVC_OMNI: Notifications icon in the browser
-
ORA_SVC_MOBILE: Mobile notifications
Script for Custom Objects
You can use a Groovy script to send notifications for custom objects.
Prerequisites:
-
Use the global function, adf.util.sendNotification (adf, map).
-
The ObjectCode needs to be explicitly passed as part of the request parameter hash map in the Groovy trigger.
-
Your custom object needs to be published.
Object |
Scenario |
Create and Assign Scripts |
---|---|---|
Custom object |
Send bell notification to the user based on the user's party ID |
try { Long recipientPartyId =
100010037456865 def messageText = 'A custom object notification
(default message).' def objectCode='CustomObject_SR_c'
def map = new HashMap(); map.put("Channels", ["ORA_SVC_BELL"]);
map.put("MessageText", messageText); map.put("RecipientPartyId",
recipientPartyId); map.put("ObjectCode", objectCode);
adf.util.sendNotification(adf,map) println("Triggered a
notification"); } catch (e) { // Log the failure in groovy
logging. Logs can be viewed in 'Runtime Messages'.
println("Failure to trigger notification from Groovy Script " +
e.getMessage()); } |
To find the Object Code for your custom object, navigate to the overview page for the object. The API name is listed in the Object Information region of that page.