-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemployeeStatusUpdate.js
More file actions
57 lines (45 loc) · 1.44 KB
/
Copy pathemployeeStatusUpdate.js
File metadata and controls
57 lines (45 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var Status = Status || {};
Status.emailEmployeeStatusChange = (function ()
{
// LCM Group
// Admin needs a script that will send an email to the project supervisor
// when the status of an employee changes
var UIoutput = {};
function afterSubmit(type)
{
if(type == "delete")
{
return;
}
notifySupervisor();
}
function notifySupervisor()
{
var employee = nlapiGetNewRecord();
var prevEmployee = nlapiGetOldRecord();
if (didStatusChange(employee, prevEmployee))
{
sendNotification(employee);
}
}
function didStatusChange(employee, prevEmployee)
{
var status = employee.getFieldValue("employeestatus");
var prevStatus = prevEmployee.getFieldValue("employeestatus");
return ((prevStatus || status) && (status !== prevStatus));
}
function sendNotification(employee)
{
var sender = nlapiGetUser();
var supervisor = employee.getFieldValue("supervisor");
var firstName = employee.getFieldValue("firstname");
var lastName = employee.getFieldValue("lastname");
var employeeStatus = employee.getFieldText("employeestatus");
var subject = "Employee Satus Change Notification";
var body = "The status of " + [firstName, lastName].join(" ") +
" has changed to " + (employeeStatus || "blank");
nlapiSendEmail(sender, supervisor, subject, body);
}
UIoutput.afterSubmit = afterSubmit;
return UIoutput;
}) ();