Servicely Administration
...
Outbound Notifications
Outbound Email Notifications
17 min
outbound email notifications provide the ability to send html emails to users based on a condition when a record is updated or created outbound notifications can be sent conditionally and can provide content that can have scripted logic and field content it should be noted that if you want a notification to be sent out multiple times for a user based on a condition, you can utilise the reminder generation docid 7ucenlrgrhqkqtdugpfns to achieve this outbound email notifications always generate a watermark, which will allow an on going communication between an email and servicely for information on how servicely handle inbound emails, please refer to inbound messaging docid\ zah49ic1z3qdqpzkk0u9t go to administration > messaging > outbound notifications menu to add/update outbound notification records configuration please note that as of release 1 10, that there are two versions of notification setup we recommend that you use “v2” going forward, for any notifications you set up field type notes / description example name string this is simply a way of identifying at a glance one outbound notification from another incident has been created priority order integer the notification with the lowest priority order and condition that matches will be sent in situations where multiple notifications have the lowest priority order and the condition meets, all the notifications with the same priority will be sent it should be noted that this happens per recipient, so it is likely that numerous different notifications get sent with different priority orders at one time for different recipients 1 active boolean this determines whether or not the notification can be sent and have its condition ran yes version choice choices are classic email notifications (v1) enhanced notifications (v2)please follow the corresponding sections below to configure your outbound notification record depending on the version you select note that we recommend you use v2 going forward | enhanced notifications (v2) | \| table | table | the table that the notification is for and condition is running against | incident | \| type | choice create update create/update scripted | this determines when a notification is sent create type notifications will only send when a record is first created, whilst the update type will run when there has been an update to the record, assuming it meets the condition scripted notifications will run when a script initiates the notification | create | \| send to initiator | boolean | this determines whether or not the person who caused this notification to trigger (normally the updated by person) will receive the notification if they are listed as a recipient this assumes that the condition has been met and it is of the lowest priority order | yes | \| process auto replies | boolean | this determines if the notification is to be sent out, was due to an update to the record that the notification is running for, from an inboudn email that has been deemed as an “auto reply” email | no | configuration enhanced notifications (v2) the outbound notification’s “enhanced notifications (v2)” version allows for multiple channels of communications out of a single configuration for example, if you have two notifications for the incident management docid\ k caxgwjtxmh6o1k9mfg3 table that you need to send to the incident’s requestor on the ticket’s creation 1 using email and 1 using microsoft teams, you will just need to create a single outbound notification record, but with two “outbound notification provider” records one for each notification channel the following are the fields you can configure when setting up an outbound notification record using version 2 (v2) field type notes / description example providers list you will need to create an outbound notification provider with type of “email”, as part of the configuration please refer to #outbound notification provider for more information condition script the condition is a server script that will be checked against the current (current) record to determine if this notification will fire the resulting boolean should be set to the variable answer if empty, the condition will always be considered true ``` answer = !current firstcontactresolved()&& current clientjournal haschanged() \| recipients | script | recipients is a server script that has access to the current (current) record to set the associated recipients of the notification this is a list of user fields and/or email addresses, and must be set in the answer variable see the recipient configuration examples section for a few different examples of what you can achieve it should be noted that if the same email address is in multiple places that have been listed as a recipient, only one email will be sent for that user, as opposed to multiple to add cc or bcc addresses, 'cc' and 'bcc' functions can be used to add users/addresses to the outbound emails note that the cc/bcc options are ignored when 'send individually' is 'true' please refer to \[#notification recipients]\(#notification recipients) for more information | ``` answer = \[ current relation("follower"), current requestor(), current requestedfor(), current email(), cc("test\@hotmail com"), bcc(current relation("secretfollower")) ]; ``` | \| context | script | using the ‘context script' you can perform more complex lookups and/or logic the 'context script' returns a map of values that can then be referenced by name in the outbound notification’s html body | ``` let requestor = current requestor(); answer = { requestor mobile requestor mobile hasvalue() ? requestor mobile() "user does not have a mobile" }; ``` | \## outbound notification provider you can create one off a v2 outbound notification record by clicking on “new” of the provider configuration related list a pop up will appear and you can start populating it example below !\[image 20250227 030901 png]\(attachments/2604171265/2603810849 png?width=1319) once you are on the outbound notification provider screen, here are what you need to configure \| field | type | notes / description | example | \| | | | | \| provider type | choice | this determines which notification channel the provider is using choices are (note that this list can change, so check back to our documentation here for most up to date list) teams \ whatsapp \ emailwe will be choosing email for email notifications | email | \| send individually | boolean | this determines if the notification should be sent individually, as opposed to including all recipients in the same email in other words, a different email is send for each recipient if this field is 'true', the cc and bcc recipients will be ignored | false | \| messaging template | reference | this is where you choose which messaging template the notification provider will use please please refer to \[#messaging template]\(#messaging template) for more information | work with summary & client journal | \| messaging account | script | this allows you to send an outbound email notification from a different messaging account this can be hard coded to be the id, or can be scripted, where as you have access to the current record the notification is running against, with "current" it should also be noted that there is a script library name outboundnotificationsupport which allows them to be defined for all outbound notification records in one place | ``` answer = "5193209cfe8711edb2530ab31ce94e28"; ``` | \| from | script | this allows you to overwrite the from address from an email being sent out note that this will require some settings to be set on the email side, so is largely dependent on your email environment in how it is set up this is important, as depending on your email settings will depend if this is used only for external users to your organisation, or both it should be noted that the email account that this from refers to must give permission to the messaging account you use to process emails to achieve this you have access to the current record the notification is running against, with "current" it should also be noted that there is a script library name outboundnotificationsupport which allows them to be defined for all outbound notification records in one place | ``` if (current company hasvalue()) { answer = current company() c supportemail(); } else { answer applicationpropertymanager getproperty("fake fallback support email"); } ``` | \| context | script | using the ‘context script' you can perform more complex lookups and/or logic the 'context script' returns a map of values that can then be referenced by name in the outbound notification’s html body | ``` let requestor = current requestor(); answer = { requestor mobile requestor mobile hasvalue() ? requestor mobile() "user does not have a mobile" }; ``` | after the notification provider record is created, then it will look similar to the example below it is an out of box outbound notification with a related outbound notification provider of type email !\[image 20250227 025937 png]\(attachments/2604171265/2604171284 png?width=1433) \## messaging template used by the outbound notification v2, this provides a reusable notification template across multiple notifications for example, if notifications for incident creation and incident client journal update, only differ in the greeting text, then the two notifications can make use of the same template but passing on its own contextual information, such as the greeting text to create one, you can click on the + icon on the empty “messaging template” field on the outbound notification provider record a pop up will appear and you can start populating it example below for emails !\[image 20250227 031143 png]\(attachments/2604171265/2604072979 png?width=1324) for provider type of “email”, the following are what you need to populate \| field | type | notes / description | example | \| | | | | \| subject | string | the subject of the email that will be sent anything within the appropriate tags will be executed see the notification content section for examples of what can be achieved please refer to \[#notification subject and body]\(#notification subject and body) for more information | incident ${current number()} has been created | \| html template | html | the body of the email that will be sent anything within the appropriate tags will be executed see the notification content section for examples of what can be achieved please refer to \[#notification subject and body]\(#notification subject and body) for more information | | for teams , you will need to provide a json template see \<https //learn microsoft com/en us/power automate/create adaptive cards> for more details for whatsapp , you will also need to provide a template see \<https //en gb facebook com/business/help/2055875911147364?id=2129163877102343> for more details it should be noted that with the upgrade, there are some examples as to how this can be set up \# configuration classic email notifications (v1) the following are the fields you can configure when setting up an outbound notification record using version 1 (v1) \| field | type | notes / description | example | \| | | | | \| send individually | boolean | this determines if the notification should be sent individually, as opposed to including all recipients in the same email in other words, a different email is send for each recipient if this field is 'true', the cc and bcc recipients will be ignored | false | \| subject | string | the subject of the email that will be sent anything within the appropriate tags will be executed see the notification content section for examples of what can be achieved please refer to \[#notification subject and body]\(#notification subject and body) for more information | incident ${current number()} has been created | \| body | html | the body of the email that will be sent anything within the appropriate tags will be executed see the notification content section for examples of what can be achieved please refer to \[#notification subject and body]\(#notification subject and body) for more information | | \| from | script | this allows you to overwrite the from address from an email being sent out note that this will require some settings to be set on the email side, so is largely dependent on your email environment in how it is set up this is important, as depending on your email settings will depend if this is used only for external users to your organisation, or both it should be noted that the email account that this from refers to must give permission to the messaging account you use to process emails to achieve this you have access to the current record the notification is running against, with "current" it should also be noted that there is a script library name outboundnotificationsupport which allows them to be defined for all outbound notification records in one place | ``` if (current company hasvalue()) { answer = current company() c supportemail(); } else { answer applicationpropertymanager getproperty("fake fallback support email"); } ``` | \| messaging account | script | this allows you to send an outbound email notification from a different messaging account this can be hard coded to be the id, or can be scripted, where as you have access to the current record the notification is running against, with "current" it should also be noted that there is a script library name outboundnotificationsupport which allows them to be defined for all outbound notification records in one place | ``` answer = "5193209cfe8711edb2530ab31ce94e28"; ``` | \| condition | script | the condition is a server script that will be checked against the current (current) record to determine if this notification will fire the resulting boolean should be set to the variable answer if empty, the condition will always be considered true | ``` answer = !current firstcontactresolved()&& current clientjournal haschanged() ``` | \| recipients | script | recipients is a server script that has access to the current (current) record to set the associated recipients of the notification this is a list of user fields and/or email addresses, and must be set in the answer variable see the recipient configuration examples section for a few different examples of what you can achieve it should be noted that if the same email address is in multiple places that have been listed as a recipient, only one email will be sent for that user, as opposed to multiple to add cc or bcc addresses, 'cc' and 'bcc' functions can be used to add users/addresses to the outbound emails note that the cc/bcc options are ignored when 'send individually' is 'true' please refer to \[#notification recipients]\(#notification recipients) for more information | ``` answer = \[ current relation("follower"), current requestor(), current requestedfor(), current email(), cc("test\@hotmail com"), bcc(current relation("secretfollower")) ]; ``` | \| context | script | using the ‘context script' you can perform more complex lookups and/or logic the 'context script' returns a map of values that can then be referenced by name in the outbound notification’s html body | ``` let requestor = current requestor(); answer = { requestor mobile requestor mobile hasvalue() ? requestor mobile() "user does not have a mobile" }; ``` | \# related configuration \## sending notification notification can be sent in two different ways, either by a record creation/update meeting the notification’s condition or by a server side script triggering the notification \### record create/update to trigger notifications to be processed against a record create or update, you will need a \[trigger]\(trigger 2333737087 html) to run on the table where the record is stored in out of box, there are such triggers configured already for the following tables interaction sla work workflow task the triggers need to be configured as per the following \| field name | value | \| | | \| table | table that you want notifications to be processed against | \| active | yes | \| trigger when? | after | \| on create | checked | \| on update | checked | \| script | ``` outboundnotification processnotifications(current, operation); ``` | \### scripted notification you can also trigger a notification via a server side script such as on \[trigger]\(trigger 2333737087 html) or \[workflow]\(workflow 2290581505 html) the following is a scripted notification example note that “current” is the tablerecord that we want to run the notification against you can also pass contextual information to the scripted notification, please refer to \[#contextual variables]\(#contextual variables) for more information // find the notification template to send let notificationrec = table("outboundnotification", "888b0a50b4fe11ffbab406d23a2a6c51"); if (notificationrec != null) { // trigger the notification! outboundnotification processdirectoutboundnotification(notificationrec, current); } \## notification recipients when sending notifications to users, there are a variety of ways you can determine who the recipients are for a notification this is a scripted field, so it allows for a level of processing, but it should be noted that at the end you will need to assign an array to the answer variable the different ways you can add recipients are as follows \### hard coded email addresses at a basic level, you can simply hard code email addresses to be sent notifications example below answer = \[ " example\@email com mailto\ example\@email com ", " admin\@servicely ai mailto\ admin\@servicely ai " ]; \### string field with an email you can also reference a string field that may hold an email example below let tolist = \[]; tolist push(current email()); //assuming the requestor has been populated, add it to the array we will be sending a notification to if (current requestor()) { tolist push(current requestor() email()); } answer = tolist; \### single reference to user it is also possible to singular reference a user record, this will automatically look at the email associated with that user record email below answer = \[ current requestor(), current requestedfor() ]; \### multiple reference to user it is also possible to multiple reference the user table, this will automatically look at the email associated with those user records example below answer = \[ current relation("follower") ]; \### advanced finally, you can use a mixture of all the above and do queries at the same time to get the required recipients example below let tolist = \[ current relation("follower"), current requestedfor(), current email(), " admin\@servicely ai mailto\ admin\@servicely ai " ]; //if there is an assignee, just email the assignee if (current assignee()) { tolist push(current assignee()); } //in this example, follower groups is a multiple reference to the group table let groupidarr = current getrelation("followergroups") map(group => group id()); //for each group, do a sub query to the user record and get each user from those groups for (let groupindex = 0; groupindex < groupidarr length; groupindex++) { let userrec = table("user") subquery("group", equal("id", groupidarr\[groupindex])) equal("active", true) query(); while (userrec next()) { tolist push(userrec email()); } } answer = tolist; \## notification subject and body when building an email notification, both of the email’s subject and body/content can be made up of a mixture of html, scripting and field name replacements you can use information on the record that the notification is being run from and use that as part of the body or subject of a notification \### direct html configuration to access and change the html of a notification directly, you can press the following button on the outbound notification body field !\[]\(attachments/2604171265/2604072988 png?width=960) \### field content replacement when writing the content of the notification, you can have the content of the field substituted in the body with the following format ${current \<fieldname>()} example ${current shortdescription()} in doing so, there are a few things to note if the field is undefined, it will be shown as blank in the notification if you are using a related field, for example ${current requestor() manager()}, it will be shown as blank if the requestor has not been entered if you are referencing a journal field, it will only show the latest entry if there are no entries, it will simply be blank \### context scripting using the 'context script' you can perform more complex lookups and/or logic the 'context script' returns a map of values that can then be referenced by name in the notification body let requestor = current requestor(); answer = { requestor mobile requestor mobile hasvalue() ? requestor mobile() "user does not have a mobile" }; !\[]\(attachments/2604171265/2604072994 png?width=646) in the above example, it will provide the user's mobile phone number within the notification if the user has one, else it will simply have the text in the notification "user does not have a mobile" other examples below \#### example 1 adding a url back to the record the notification is for first, write the context script to get a link back to the record notes 1\ "current" is the javascript object representation of the record that the notification is run for 2\ "selfservice" is the name of the view of the record you want to show to the user when they click on the link 3\ "record\\ url" is the name that you want to reference in the email notification body let recordurl = current getlinkforui({create false, aspect "selfservice"}); answer = { record url recordurl }; then, you may add ${record\\ url} on the email notification body, wherever you want to place the url onto example below please click here to view the ticket ``` example 2 adding attachment to add all attachments of a record the notification is for, the following line can be added to the context script (contextscript) field on the outbound notification template // the second and fourth parameters for the copyrecordattachmentstoemail function below are the attachment field names for the current record and the system email record respectively attachmentmanager copyrecordattachmentstoemail(current, "attachments", systememailrec, "attachments"); to add a subset of attachments of a record the notification is for, the following lines can be added (and modified as needed) to the context script (contextscript) field on the outbound notification template const attachments = current attachments() filter((a) => a mimetype() endswith("pdf")); // this will only return pdf attachments from current record attachmentmanager copyattachmentstoemail(attachments, systememailrec, "attachments"); watermark in addition to the content within the notification, each notification will automatically include a generated number at the bottom of the email body, which will be used as a watermark the watermark is used to tie a notification to a record this will allow users to reply to an email and assuming it meets an inbound message record and its condition, will know what record to update based on this contextual variables new in release 1 9 you can also optionally provide context to the outbound notification when you are triggering the notification using server side script ( #scripted notification ) example below is if we want to dynamically specify the following in the notification template which email address we are sending from which messaging account to use who to send the notification to some specific information for the notification content (subject and body) sample server side script below that has been configured to trigger an outbound notification let current = table("incident", "7a1b46c2f7a011ee99a60242ac140003"); // current can be any record but for this example we are making use of a particular incident // find the notification template to send let notificationrec = table("outboundnotification", "74f785e005b611efa9130242ac140002"); if (notificationrec != null) { // trigger the notification! let context = { fromaddress "sender\@servicely ai", messagingaccount "a82a40b205b711efa9130242ac140002", emailrecipients \["someone outthere\@gmail com"], bodyintro "hello world!", emailsubject "someone out there", bodyfromscript "you need to check out my email!" }; outboundnotification processdirectoutboundnotification(notificationrec, current, { context context }); } then, to make use of the context object provided in the outbound notification template, you can for example include it in any of the following notification’s attributes note that some of the fields below are placed in different tables (outbound notification, outbound notification provider and messaging template), if you are using the newer and recommended v2 notification version from answer = context fromaddress; messaging account answer = context messagingaccount; recipients answer = context emailrecipients; context script let texttosay = context bodyintro; answer = { texttosay texttosay } subject incident updated by ${context emailsubject} body / html template \<p>${texttosay}\</p> \<p>${context bodyfromscript}\</p> a screenshot showing the generated email record using the sample set up shown above