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

titleStringYN

Return:

Type

Description

VoidThis method does not return a value.


 ss.importIncludeScript('SimpleEmailTemplate');
 const htmlTemplate = new SimpleEmailTemplate('');
 htmlTemplate.setTitle(`${current.number} ${current.subject}`);

setBodyHeader(bodyHeader)


This method sets the header of text body of email notification.

Parameter(s):

Name

Type

Mandatory

Default value

bodyHeaderStringYN

Return:

Type

Description

VoidThis method does not return a value.


  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.

Parameter(s):

Name

Type

Mandatory

Default value

bodyTextStringYN

Return:

Type

Description

VoidThis method does not return a value.


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)


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

commentStringYN

Return:

Type

Description

VoidThis method does not return a value.


ss.importIncludeScript('SimpleEmailTemplate');
const htmlTemplate = new SimpleEmailTemplate('');
htmlTemplate.setComment(`Comment: ${current.additional_comments}`)

getTitle(title)


This method returns the main header of notification.

Return:

Type

Description

StringThe main header of notification.


 email.setBody(htmlTemplate.formEmailTemplate());
 ss.info(htmlTemplate.getTitle()); // Result: INC0000XXX Email not working

getBodyHeader(bodyHeader)


This method returns the main header of text body.

Return:

Type

Description

StringThe main header of text body.


email.setBody(htmlTemplate.formEmailTemplate());
ss.info(htmlTemplate.getBodyHeader()); // Result: Incident INC0000XX Email not working

getBodyText(bodyText)


This method returns the main text body.

Return:

Type

Description

StringThe main text body.


email.setBody(htmlTemplate.formEmailTemplate());
ss.info(htmlTemplate.getBodyText()); // Result: Description 27.01.2022 Could not log in to my email, the error 'No access'. 

getComment(comment)


This method returns the comment text.

Return:

Type

Description

StringThe comment text.


) {
    ss.importIncludeScript('NotificationsInApprovalContextUtility');
    const notificationUtility = new NotificationsInApprovalContextUtility(current);
    return notificationUtility.getComments();
})(current, template, email, event);

getButtons(buttons)


This method returns the array of buttons.

Return:

Type

Description

ArrayThe array of buttons.


ss.importIncludeScript('SimpleEmailTemplate');
const htmlTemplate = new SimpleEmailTemplate('');
ss.info(htmlTemplate.getButtons()); // Results: [{"text":"Approve","url":"https:\/\/instance.example.com\/","color":"#05C270"},{"text":"Reject","url":"https:\/\/instance.example.com\/","color":"#F73422"}]

addButton(button)


This methods adds a new button to array of buttons.
Parameter(s):

Name

Type

Mandatory

Default value

textStringYN
urlStringYN
colorStringYN
buttonArrayArrayYN

Return:

Type

Description

ArrayThe base of buttons array with the new one.


    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)}`);

removeButton(button)


 This method removes the last added button.

  if (current.state === '2') { // Incident in the 'In Progress' state
    htmlTemplate.removeButton();
}

removeAllButtons(buttons)


This method removes all added buttons.

 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

propertyNameStringYN
inputString/NumberYN
propertyTitleStringYN


if (current.state === '7') { Incident in the 'Completed' state
    htmlTemplate.setProperty('bodyText', 'Incident information needed', 'Body Text'); // Result: Information needed
    ss.info(htmlTemplate.getBodyText()); 
  }

formEmailTemplate()


This method creates and returns HTML template based on set properties.

Return:

Type

Description

StringThe HTML template.


formEmailTemplate() {
        //text formatter - \n to <br>
        const bodyText = this.bodyText.toString().replace(/\n/g, '<br>');

        //creates space between bodyHeader and bodyText
        let bodySplitter = '';
        if (this.bodyHeader !== '' && this.bodyHeader !== '') {
            bodySplitter = '<br><br>';
        }