Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
This class allows the client-side script to execute the code on the server-side using Script Includes. it is used to create branded notifications.
setTitle(title)
This method sets the main header of email notification.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
title | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
ss.importIncludeScript('SimpleEmailTemplate');
const htmlTemplate = new SimpleEmailTemplate('');
htmlTemplate.setTitle(`${current.number} ${current.subject}`); |
setBodyHeader(bodyHeader)
This method sets the header of notification text body.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
bodyHeader | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
let bodyHeaderTemplate = `<a href="${currentRecordURL}">${emailSubject}</a> <br><br> <br> The state changedof ${current.number} changed, new state: ${current.getDisplayValue('state')}.`; if(current.state == '3'){ //Postponed bodyHeaderTemplate += ` Repeated`Repeated request : ${current.getDisplayValue('resubmission')} ` ; } bodyHeaderTemplate += ` <br><br> You `<br><br>You can add information by replying to this letter, do not change the subject of the letter. `; htmlTemplate.setBodyHeader(bodyHeaderTemplate); |
setBodyText(
bodyHeaderbodyText)
This method sets the header of main text body of email notification.
Parameter(s):
Name | Type | Mandatory | Default value |
---|
bodyText | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
setBodyHeader(bodyHeader) {
this.setProperty('bodyHeader', bodyHeader, 'You have a new approval ticket');
} |
setBodyText(bodyText)
This method sets the main text body of email notification.
Parameter(s):
Name
Type
Mandatory
Default value
Return:
Type
Description
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
setBodyText(bodyText) { this.setProperty('bodyText', bodyText, 'Youconst htmlTemplate = new SimpleEmailTemplate(approvalItem.getDisplayValue()); const allApproversObject = JSON.parse(current.additional_parameter); htmlTemplate.setBodyText(`Dear ${current.getDisplayValue('approver_id')}, you need to approve or reject the ticket.'); } <a href="${ApprovalItemURL}">${approvalItem.getDisplayValue()}</a> The list of the approval tickets: ${transformToTemplateList(allApproversObject)}`); |
setComment(comment)
This method sets the email notification comment:
- puts it in an area with a grey background
- highlights it italic.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
comment | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
setComment(comment) {
this.setProperty('comment', comment, 'Leave your comment here');
} |
ss.importIncludeScript('SimpleEmailTemplate');
const htmlTemplate = new SimpleEmailTemplate('');
htmlTemplate.setComment(`Comment: ${current.additional_comments}`); |
getTitle()
This method returns the main header of notification.
Return:
Type | Description |
---|---|
String | The main header of notification. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
getTitle() {
return this.title;
} |
const htmlTemplate = new SimpleEmailTemplate('');
htmlTemplate.setTitle(`${current.number} ${current.subject}`);
ss.info(htmlTemplate.getTitle()); // Result: INC0000XXX Email not working |
getBodyHeader()
This method returns the main header of text body.
Return:
Type | Description |
---|---|
String | The main header of text body. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
getBodyHeader() { ss.importIncludeScript('SimpleEmailTemplate'); const htmlTemplate = new SimpleEmailTemplate(''); htmlTemplate.setBodyHeader(`Incident return this.bodyHeader; } |
${current.number} ${current.subject}`);
ss.info(htmlTemplate.getBodyHeader()); // Result: Incident INC0000XX Email not working |
getBodyText()
This method returns the main text body.
Return:
Type | Description |
---|---|
String | The main text body. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
getBodyText() {
return this.bodyText;
} |
ss.importIncludeScript('SimpleEmailTemplate');
const htmlTemplate = new SimpleEmailTemplate('');
htmlTemplate.setBodyText(`Description ${current.description}`);
ss.info(htmlTemplate.getBodyText()); // Result: Description 27.01.2022 Could not log in to my email, the error 'No access'. |
getComment()
This method returns the comment text.
Return:
Type | Description |
---|---|
String | The comment text. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
getComment() {
return this.comment;
} |
ss.importIncludeScript('SimpleEmailTemplate');
const htmlTemplate = new SimpleEmailTemplate('');
htmlTemplate.setComment(`Comment: ${current.additional_comments}`);
ss.info(htmlTemplate.getComment()); // Result: Need more information |
getButtons()
This method returns the array of buttons.
Return:
Type | Description |
---|---|
Array | The array of buttons. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
getButtons() {
return this.buttons;
} |
ss.importIncludeScript('SimpleEmailTemplate');
const htmlTemplate = new SimpleEmailTemplate('');
htmlTemplate.addButton('Approve', 'https://instance.example.com');
ss.info(htmlTemplate.getButtons()); // Results: [{"text":"Approve","url":"https:\/\/instance.example.com\/","color":"#05C270"},{"text":"Reject","url":"https:\/\/instance.example.com\/","color":"#F73422"}] |
addButton()
This methods adds a new button to array of buttons.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
text | String | Y | N |
url | String | Y | N |
color | String |
N | N | ||
buttonArray | Array | Y | N |
Return:
Type | Description |
---|---|
Array | The base of buttons array with the new one. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
addButton(text, url, color = '#E31450') {
const button = {
"text": text,
"url": url,
"color": color
}; |
ss.importIncludeScript('SimpleEmailTemplate');
const htmlTemplate = new SimpleEmailTemplate('');
htmlTemplate.addButton('Approve', 'https://instance.example.com'); |
removeButton()
This method removes the last added button.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
removeButton() { ss.importIncludeScript('SimpleEmailTemplate'); const htmlTemplate = new SimpleEmailTemplate(''); htmlTemplate.addButton('Approve', 'https://instance.example.com'); if (current.state === '2') { // Incident in the 'In Progress' state thishtmlTemplate.buttons.popremoveButton(); } |
removeAllButtons(
buttons)
This method removes all added buttons.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
removeAllButtons() { this.buttons = []; ss.importIncludeScript('SimpleEmailTemplate'); const htmlTemplate = new SimpleEmailTemplate(''); htmlTemplate.addButton('Approve', 'https://instance.example.com'); htmlTemplate.addButton('Reject', 'https://instance.example.com'); if (current.state === '3') { Incident in the 'Postponed' state htmlTemplate.removeAllButtons(); } |
setProperty(propertyName, input, propertyTitle)
This method sets internal method for input type validation.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
propertyName | String | Y | N |
input | String/Number | Y | N |
propertyTitle | String | Y | N |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
setProperty(propertyName, input, propertyTitle) { if (typeof input === 'string' || typeof input === 'number') { this[propertyName] = input; } else { ss.addErrorMessage(`Invalid data type.`); } }ss.importIncludeScript('SimpleEmailTemplate'); const htmlTemplate = new SimpleEmailTemplate(''); htmlTemplate.setProperty('bodyText', Need information about the incident', 'Body Text'); ss.info(htmlTemplate.getBodyText()); // Result: Need information about the incident |
formEmailTemplate()
This method creates and returns HTML template based on set properties.
Return:
Type | Description |
---|---|
String | The HTML template. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
formEmailTemplate() { //text formatter - \n to <br> const bodyText = this.bodyText.toString().replace(/\n/g, '<br>ss.importIncludeScript('SimpleEmailTemplate'); const htmlTemplate = //creates space between bodyHeader and bodyText let bodySplitter = ''; if (this.bodyHeader !== '' && this.bodyHeader !== '') { bodySplitter = '<br><br>'; }new SimpleEmailTemplate(''); htmlTemplate.setTitle(`${current.number} ${current.subject}`); htmlTemplate.setComment(`Comment: ${current.additional_comments}`); htmlTemplate.setBodyHeader(`Incident ${current.number} ${current.subject}`); htmlTemplate.setBodyText(`Description: ${current.description}`); email.setBody(htmlTemplate.formEmailTemplate()); |
Table of Contents | ||||||
---|---|---|---|---|---|---|
|