Just incase full script: having a doubt on mailaddress part as it is not declared
gs.include('validators');
//These should be defined as properties (notification sciprt HR Case Resolved)
var REJECT_SUBJ = "reject";
var REOPEN_SUBJ = "reopen";
var ACCEPT_SUBJ = "accept";
var senderSysID = email.from_sys_id.toString();
//string senders mail address from header info
// var SEARCH_STRING = "smtp.mailfrom=";
// var headers = email.headers;
// var smtp_mailfrom_pos = headers.indexOf(SEARCH_STRING);
// var email_start_pos = smtp_mailfrom_pos + SEARCH_STRING.length;
// var headers_tail = headers.substr(email_start_pos, headers.length);
// var email_end_pos = headers_tail.indexOf(' ');
// var mailaddress = headers_tail.substr(0, email_end_pos + 1).trim();
// mailaddress = mailaddress.replace(';', '');
if (sys_email.headers.indexOf("X-Original-Sender:dse@eumail.docusign.net")>-1) {
var emails = "dse@eumail.docusign.net";
} else {
var replyTo = sys_email.reply_to;
var emails = email.from.toLowerCase();
if (replyTo != '' && replyTo.indexOf("<") > -1) {
var emStart = replyTo.indexOf("<") + 1;
var emEnd = replyTo.indexOf(">");
if (emStart >= 0) {
emails = replyTo.substr(emStart, emEnd - emStart).trim();
}
} else if (replyTo != '') {
emails = replyTo.toString();
}
}
//update on active cases
if (current.getTableName() == "sn_hr_core_case" && current.getValue('state') != 3 && current.getValue('state') != 7) {
//gs.info('xxx1 '+ mailaddress);
if (current.getValue('u_sender_email') == mailaddress || current.opened_for.email == mailaddress || current.opened_by.email == mailaddress || current.subject_person.email == mailaddress) {
//if rejection email, set state back to work in progress
if ((email.subject.indexOf(REJECT_SUBJ) !== -1) ||
(email.subject.indexOf(REOPEN_SUBJ) !== -1)) {
//only for awaiting acceptance state
if (current.getValue('state') == 20) {
current.state = 18;
}
}
//If accept email close the case.
if (email.subject.indexOf(ACCEPT_SUBJ) !== -1) {
//only for awaiting acceptance state
if (current.getValue('state') == 20) {
current.state = 3;
}
}
}
if (current.subject_person.email != mailaddress && current.opened_for.email != mailaddress && current.opened_by.email != mailaddress && current.u_sender_email != mailaddress && !isInList(current.watch_list, mailaddress)) {
current.work_notes = "reply from : " + mailaddress + "\n\n" + email.body_text;
} else {
current.comments = "reply from: " + mailaddress + "\n\n" + email.body_text;
}
current.update();
} else if (current.state == 3 || current.state == 4) {
if (email.subject.indexOf("Tikettisi on ratkaistu") > -1) {
} else {
var grHR = new GlideRecord('sn_hr_core_case');
grHR.initialize();
grHR.priority = current.priority;
grHR.opened_for = current.opened_for;
grHR.subject_person = current.subject_person;
grHR.contact_type = 'email';
grHR.topic_category = current.topic_category;
grHR.topic_detail = current.topic_detail;
grHR.hr_service = current.hr_service;
grHR.state = 10;
grHR.u_sender_email = current.u_sender_email;
grHR.watch_list = current.watch_list;
grHR.description = current.description;
grHR.rich_description = current.rich_description;
grHR.short_description = '[REOPENED ' + current.number + '] ' + current.short_description;
grHR.parent = current.sys_id;
grHR.comments = "Reply from: " + mailaddress + "\n\n" + email.body_text;
grHR.insert();
}
}
function isInList(userList, emailAdd) {
var assgUser = new GlideRecord('sys_user');
assgUser.addQuery('sys_id', 'IN', userList);
assgUser.addQuery('email', emailAdd);
assgUser.addQuery('active',true);
assgUser.query();
if (assgUser.next()) {
return true;
} else if (userList.toString().indexOf(emailAdd) > -1)
return true;
return false;
}