Close
Thank you for your feedback.

Notification example: assignment notification

Notification example: assignment notification

In this notification example, enhance the To Do application to send an email notification when someone is assigned a task.

Before you begin

Role required: admin

About this task

The email notification is triggered by an event, which is triggered by a business rule. Events can be triggered by business rules and, in turn, reacted to elsewhere. This event is triggered by the business rule created in the next procedure and will, in turn, trigger the email notification.

Procedure

  1. Navigate to System Policy > Events > Registry.

  2. Click the New to create an event registry record.</li>

  3. Select the To_Do table.

  4. Type A To Do has been assigned in the Description field.

    Fired by is basically a comment to remind you where the events come from. We select Business Rule.

    Creating the event registry

  5. Click Submit.

  6. Navigate to System Definition > Business Rules.

  7. Click New to create a business rule.

  8. Fill in the fields as follows:

    • Name: To Do Assigned
    • Table: to_do
    • Run at: server
    • When: after
    • Insert: true
    • Update: true

  9. Enter a condition to trigger the business rule whenever the Assigned to field is changed or initially populated:

    <font face = "Courier">
    current. u_assigned_to. changes ( ) </font face = "Courier">

  10. Enter a script to add a to_do.assigned event.

  11. In addition to the event name and the current record, specify two additional parameters (user’s ID and Name).

    <font face = "Courier">
    gs. eventQueue ( "to_do.assigned" , current , gs. getUserID ( ) , gs. getUserName ( ) ) ; </font face = "Courier">

    The example business rule

  12. Click Submit.

  13. Test that the business rule is creating the event as follows:

    1. Change the value in the Assigned to field of an existing To Do record or create a new record and specify an Assigned to.
    2. Navigate to System Policy > Events > Event log and look for an event with the name to_do.assigned.
    3. To make this easier, you can sort the event log in descending order by created.

  14. Navigate to System Notification > Email > Notifications.

  15. Click New to create an email notification.

  16. Fill in the following fields:

    • Name: To Do Assigned
    • Event name: to_do.assigned
    • Table name: to_do

    The User field specifies to whom the email should be sent. In this case, send it to the Assigned to user.

  17. In User field, enter u_assigned_to.

    Sometimes, you do not want notifications to be sent to the person who triggered the notification. In this case, clear the Send to event creator check box. Select this option to see all the notifications.

  18. Enter the Subject of the email as To Do Assigned.

  19. Under Select variables, click Due Date.

    You will see text added to the message text box which causes the value of the due date to be inserted. You can change the label (Due Date in this case) which was provided automatically. Use the same method to add two more variables to the message text: Priority and Short Description.

    Example email notification

  20. Click Submit.

  21. Warning: Do not use your own POP server for this exercise. You should have a test account set up on your mail server (see the administrator of your mail system). It may download the contents of your POP account. You may choose to skip configuring Glide to use an email server and just check the Glide email log instead of sending an actual email (see final step below).

    Navigate to System Properties > Email.

  22. Under SMTP Server Settings, enter the outgoing mail server, outgoing mail address, the mail server password, and outgoing mail display name.

  23. If you are using a POP server, enter the POP server, incoming POP mail account name (do not include the @ and server name here), and incoming POP mail account password.

    At the bottom of the form is a space where a test email account can be provided to direct emails to it instead of the actual email addresses. Rather than test emails sent to the test users, place your own email address here.

    Email properties

  24. Click Save.

  25. Test the assignment notifications.

    1. Assign some To Do records.
    2. Navigate to System Logs Email to see that status of generated emails.

      You should receive email notifications in a few moments.

Products > ServiceNow Platform > Notifications; Versions > Helsinki