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 simply create branded notifications.

 property {string} title - Main header of notification
{string} bodyHeader - Header of text body
 {string} bodyText - Main text area
 {string} comment - Comment wraps in area with grey background, also becomes italic 
 
{array} buttons - Array of buttons (better generate via addButton())

setTitle(title)

Supposed initialising with specified title    @param {string} title - Main header of notification
     */

setTitle(title)


This method sets the main header of email notification.

Parameter(s):

Name

Type

Mandatory

Default value

titleStringYN

Return:

Type

Description

VoidThis method does not return a value.


Code Block
languagejs
themeEclipse
titlesetTitle
linenumberstrue
 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

bodyHeaderStringYN

Return:

Type

Description

VoidThis method does not return a value.


Code Block
languagejs
themeEclipse
titlesetBodyHeader
linenumberstrue
  let bodyHeaderTemplate = `<a href="${currentRecordURL}">${emailSubject}</a> <br> The state of ${current.number} changed, new state: ${current.getDisplayValue('state')}.`;
  if(current.state == '3'){ //Postponed
      bodyHeaderTemplate += `Repeated request: ${current.getDisplayValue('resubmission')}`;       
}
  bodyHeaderTemplate += `<br><br>You can add information by replying to this letter, do not change the subject of the letter. `;
  htmlTemplate.setBodyHeader(bodyHeaderTemplate);

setBodyText(bodyText)


This method sets the main text body of email notification.

setBodyHeader(bodyHeader)

This method sets header of text body of email notification  * @param {string} bodyHeader - Header of text body

Parameter(s):

Name

Type

Mandatory

Default value

paramName
bodyTextStringYN

Return:

Type

Description

VoidThis method does not return a value.


Code Block
languagejs
themeEclipse
titlesetBodyText
(bodyText)Sets main text body of email notification  @param {string} bodyText - Main text body
linenumberstrue
const htmlTemplate = new SimpleEmailTemplate(approvalItem.getDisplayValue());
const allApproversObject = JSON.parse(current.additional_parameter);
htmlTemplate.setBodyText(`Dear ${current.getDisplayValue('approver_id')}, you need to approve <a href="${ApprovalItemURL}">${approvalItem.getDisplayValue()}</a> The list of the approval tickets: ${transformToTemplateList(allApproversObject)}`);

setComment(comment)

Sets comment of email notification (after wraps

This method sets the email notification comment:

  • puts it in an area with a grey
background, also becomes italic)    @param {string} comment - Comment text
  • background 
  • highlights it italic.

Parameter(s):

Name

Type

Mandatory

Default value

commentStringYN

Return:

Type

Description

VoidThis method does not return a value.


Code Block
languagejs
themeEclipse
titlesetComment
linenumberstrue
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

StringThe main header of notification.


Code Block
languagejs
themeEclipse
titlegetTitle
linenumberstrue
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

StringThe main header of text body.


Code Block
languagejs
themeEclipse
titlegetBodyHeader
linenumberstrue
 ss.importIncludeScript('SimpleEmailTemplate');
 const htmlTemplate = new SimpleEmailTemplate('');
 htmlTemplate.setBodyHeader(`Incident ${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

StringThe main text body.


Code Block
languagejs
themeEclipse
titlegetBodyText
linenumberstrue
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

StringThe comment text.


Code Block
languagejs
themeEclipse
titlegetComment
linenumberstrue
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

ArrayThe array of buttons.


Code Block
languagejs
themeEclipse
titlegetButtons
linenumberstrue
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

textStringYN
urlStringYN
colorStringNN
buttonArrayArrayYN

Return:

Type

Description

ArrayThe base of buttons array with the new one.


Code Block
languagejs
themeEclipse
titleaddButtons
linenumberstrue
ss.importIncludeScript('SimpleEmailTemplate');
const htmlTemplate = new SimpleEmailTemplate('');
htmlTemplate.addButton('Approve', 'https://instance.example.com');

removeButton()


 This method removes the last added button.

Code Block
languagejs
themeEclipse
titleremoveButton
linenumberstrue
ss.importIncludeScript('SimpleEmailTemplate');
const htmlTemplate = new SimpleEmailTemplate('');
htmlTemplate.addButton('Approve', 'https://instance.example.com');
if (current.state === '2') { // Incident in the 'In Progress' state
    htmlTemplate.removeButton();
}

removeAllButtons()


This method removes all added buttons.

Code Block
languagejs
themeEclipse
titleremoveAllButtons
linenumberstrue
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();
 }

 
getTitle(title)

@returns {string} Main header of notification 

getBodyHeader(bodyHeader)

* @returns {string} Header of text body

getBodyText(bodyText)

@returns {string} Main text body

getComment(comment)

 @returns {string} Comment text

getButtons(buttons)

 @returns {string} Comment text

addButton(button)

Add button to array of buttons
     * @param {string} text - Button text
     * @param {string} url - Url for button action
     * @param {string} color - string in HEX format (e.g. default #E31450 - corporate red)
     * @param {array} buttonArray - Array of buttons, that will be modified in that method
     * @returns {array} base array buttons plus new one

removeButton(button)

 Removes the last added button

removeAllButtons(buttons)

 Removes all added buttons

setProperty(propertyName, input, propertyTitle)


Internal This method sets internal method for input type validation
     * @param {string} propertyName - Name of property to validate
     * @param {any} input - Given input from 'Set' methods
     * @param {string} propertyTitle - Title of property for error text
     */

formEmailTemplate()

.

Parameter(s):

Name

Type

Mandatory

Default value

propertyNameStringYN
inputString/NumberYN
propertyTitleStringYN


Code Block
languagejs
themeEclipse
titlesetProperty
linenumberstrue
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 Creates HTML template for email notification getting properties from class object
     * @returns {string} HTML Template 
.

Return:

Type

Description

StringThe HTML template.


Code Block
languagejs
themeEclipse
titleformEmailTemplate
linenumberstrue
ss.importIncludeScript('SimpleEmailTemplate');
const htmlTemplate = 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
absoluteUrltrue
classfixedPosition
printablefalse