Skip to content
SamuelPlentz edited this page Feb 13, 2020 · 7 revisions

Creates a custom subject prefix using current date and time as a case reference number. The case reference number uses the following format [Prefix-yyMMddHHmm] where the Prefix can be specified by a variable.

It is added in front of the current subject and as a reference text in the body.

Script

// create timestampID
var date = new Date();

var yy = date.getFullYear().toString().substr(2, 2);
var mm = (date.getMonth() + 1).toString();
var dd = date.getDate().toString();
var hh = date.getHours().toString();
var nn = date.getMinutes().toString();

if (mm.length < 2) mm = "0" + mm;
if (dd.length < 2) dd = "0" + dd;
if (hh.length < 2) hh = "0" + hh;
if (nn.length < 2) nn = "0" + nn;

var timestampID = yy + mm + dd + hh + nn;


// combine prefix and timestampID to the caseID if the variable was set
var caseID = timestampID;
if(mVariables.length >= 1) caseID = mVariables[0] + "-" + timestampID;


// add caseID in front of the current subject
var subjectField = this.mWindow.document.getElementById('msgSubject');
if(subjectField)
{
  let subject = "[" + caseID + "] " + subjectField.value;
  subjectField.value = subject;
}


return "Reference number: " + caseID + "\n";

Usage

Using this script in your template (where AREF can be any other prefix or ommitted):

[[SCRIPT=CaseNumber|AREF]]

would resolve to:

Reference number: AREF-2001311245

Additionally the subject will be prefixed by: [AREF-2001311245]