Wiki source code of Notification
Hide last authors
3.2 | 1 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %) | |
2 | Api to send emails or SMS using a notification template. Notification templates can be defined in Administration tab, "Workflows and Notifications" menu and "Notifications Templates" menu | ||
3 | |||
4 | (% style="font-family: sans-serif; font-style: normal; text-align: start;" %) | ||
5 | == (% style="font-size: 22.54px; background-color: rgb(245, 245, 245);" %)Functions(%%) == | ||
6 | |||
7 | (% style="font-family: sans-serif; font-style: normal; text-align: start;" %) | ||
8 | === (% style="font-size: 20.44px;" %)init(template)(%%) === | ||
9 | |||
10 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %) | ||
11 | Init the notification with the template. template in an Entity object. | ||
12 | |||
13 | (% style="font-family: sans-serif; font-style: normal; text-align: start;" %) | ||
14 | === (% style="font-size: 20.44px;" %)setFrom(email, title)(%%) === | ||
15 | |||
16 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %) | ||
17 | Set the sender informations. | ||
18 | |||
6.1 | 19 | * email is a string representing the email address of the sender. | |
20 | * title is a string representing his name. | ||
3.2 | 21 | ||
22 | (% style="font-family: sans-serif; font-style: normal; text-align: start;" %) | ||
23 | === (% style="font-size: 20.44px;" %)setReplyTo(email, title)(%%) === | ||
24 | |||
25 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %) | ||
26 | Set the "reply to" informations. | ||
27 | |||
6.1 | 28 | * email is a string representing the email address of the sender. | |
29 | * title is a string representing his name. | ||
3.2 | 30 | ||
31 | (% style="font-family: sans-serif; font-style: normal; text-align: start;" %) | ||
32 | === (% style="font-size: 20.44px;" %)setTo(recipient, group)(%%) === | ||
33 | |||
34 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %) | ||
35 | Set the recipient informations | ||
36 | |||
37 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %) | ||
38 | * recipient is either : | ||
4.1 | 39 | (% style="font-size: 14px;" %) | |
3.2 | 40 | ** a string representing an email address | |
41 | ** an Entity object representing a User or a Group | ||
42 | ** an Array of Entity objects of Users or Groups | ||
43 | * group is an Entity object representing a group used for delegation | ||
44 | |||
4.1 | 45 | (% style="font-family: sans-serif; font-style: normal; text-align: start;" %) | |
46 | === (% style="font-size: 20.44px;" %)setCc(recipient)(%%) === | ||
47 | |||
3.2 | 48 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %) | |
4.1 | 49 | Set the copy informations | |
3.2 | 50 | ||
4.1 | 51 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %) | |
52 | * recipient is either : | ||
53 | (% style="font-size: 14px;" %) | ||
54 | ** a string representing an email address | ||
55 | ** an Entity object representing a User or a Group | ||
56 | ** an Array of Entity objects of Users or Groups | ||
57 | |||
58 | (% style="font-family: sans-serif; font-style: normal; text-align: start;" %) | ||
59 | === (% style="font-size: 20.44px;" %)setBCc(recipient)(%%) === | ||
60 | |||
61 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %) | ||
62 | Set the copy informations | ||
63 | |||
64 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %) | ||
65 | * recipient is either : | ||
66 | (% style="font-size: 14px;" %) | ||
67 | ** a string representing an email address | ||
68 | ** an Entity object representing a User or a Group | ||
69 | ** an Array of Entity objects of Users or Groups | ||
70 | |||
71 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start;" %) | ||
72 | ((( | ||
73 | (% style="font-family: sans-serif; font-style: normal; text-align: start;" %) | ||
74 | === (% style="font-size: 20.44px;" %)setVariable(name, data)(%%) === | ||
75 | |||
76 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %) | ||
77 | Set a variable in the javascript context used to compose the notification. Subject and Body of the notification template can be composed dynamically with variable resolution using the following syntax : ${data.rqTitle} | ||
78 | |||
79 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %) | ||
80 | * name is the variable name, for example "data" | ||
81 | * data is an Entity object or a basic javascript object | ||
82 | |||
83 | ((( | ||
84 | (% style="font-family: sans-serif; font-style: normal; text-align: start;" %) | ||
85 | === (% style="font-size: 20.44px;" %)compose()(%%) === | ||
86 | |||
87 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %) | ||
88 | Build the notification using the templates, parameters and variables set and returns en Entity object representing the notification. The notification can be modified before being sent. | ||
89 | ))) | ||
90 | ))) | ||
91 | |||
92 | |||
93 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start;" %) | ||
94 | ((( | ||
95 | (% style="font-size: 14px;" %) | ||
96 | ((( | ||
97 | (% style="font-family: sans-serif; font-style: normal; text-align: start;" %) | ||
98 | === (% style="font-size: 20.44px;" %)send()(%%) === | ||
99 | |||
100 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %) | ||
7.1 | 101 | Compose and send the notification. The notification is placed is the notification queue for asynchronous processing | |
4.1 | 102 | ))) | |
103 | ))) | ||
104 | |||
105 | |||
106 | (% style="text-align: start;" %) | ||
107 | ((( | ||
108 | ((( | ||
109 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start;" %) | ||
110 | === (% style="font-size: 20.44px;" %)send(notification)(%%) === | ||
111 | |||
112 | (% style="text-align: start;" %) | ||
7.1 | 113 | (% style="line-height: 19.6px;" %)Send the notification. The notification is placed is the notification queue for asynchronous processing. | |
4.1 | 114 | ||
115 | * notification is an Entity object representing the notification. This object is the result of the compose function | ||
116 | ))) | ||
117 | ))) | ||
118 | |||
119 | |||
120 | |||
121 | |||
122 | |||
123 | (% style="font-family: sans-serif; font-style: normal; text-align: start;" %) | ||
6.1 | 124 | === (% style="color: rgb(34, 34, 34); font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; line-height: 19.6px; text-align: start; background-color: rgb(245, 245, 245);" %)Example:(%%) === | |
4.1 | 125 | ||
126 | {{code language="javascript"}} | ||
127 | var notif = new Notification(); | ||
6.1 | 128 | var template = sysNotificationTemplate.Get('402881e650a9d76c0150b7f4299d29ce'); | |
129 | notif.init(template); | ||
4.1 | 130 | notif.setVariable("data", data); | |
131 | |||
132 | notif.setTo("user1@gmail.com"); | ||
133 | notif.setTo("user2@gmail.com"); | ||
134 | notif.setFrom("noreply@requea.com"); | ||
135 | notif.send(); | ||
136 | {{/code}} |