Newer
Older
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
import("Contact_lib");
import("Keyword_lib");
import("Employee_lib");
import("system.translate");
import("system.notification");
import("KeywordRegistry_basic");
import("Sql_lib");
import("system.db");
import("system.vars");
import("system.neon");
import("system.tools");
var planningObj = JSON.parse(vars.get("$param.PlanningIds_param"));
var status = vars.get("$field.STATUS");
var responsible = vars.get("$field.RESPONSIBLE");
var table = "FORECAST";
var cols;
var vals;
var planningIds;
planningIds = planningObj.filter(function(oneObj){
var cond = oneObj["STATUS"] != $KeywordRegistry.forecastStatus$locked();
if(status)
{
cond = cond || tools.currentUserHasRole("INTERNAL_ADMINISTRATOR");
}
return cond;
}).map(function(oneObj)
{
return oneObj["FORECASTID"];
});
if(status)
{
cols = ["STATUS"];
vals = [status];
}
else if(responsible)
{
cols = ["RESPONSIBLE_CONTACT_ID"];
vals = [responsible];
}
if(planningIds.length > 0)
{
db.updateData(table, cols, null, vals, newWhere("FORECAST.FORECASTID", planningIds, SqlBuilder.IN()).toString());
}
var notUpdatedRecordsLength = (planningObj.length - planningIds.length);
var descriptionText = "%0 out of %1 records were changed to \"%2\".\n %3 record/s could not be updated.";
var captionStatus = translate.withArguments("%0 status was/were changed", [planningIds.length]);
var captionResponsible = translate.withArguments("%0 responsilbe/s was/were changed", [planningIds.length]);
var descriptionStatus = translate.withArguments(descriptionText, [planningIds.length, planningObj.length, KeywordUtils.getViewValue($KeywordRegistry.forecastStatus(), status), notUpdatedRecordsLength]);
var descriptionResponsible = translate.withArguments(descriptionText, [planningIds.length, planningObj.length, ContactUtils.getFullTitleByContactId(responsible), notUpdatedRecordsLength]);
var notificationConfig = notification.createConfig()
.addUserWithId(EmployeeUtils.getCurrentUserId())
.forcedPriority(notification.PRIO_NONE)
.notificationType("_____SYSTEM_NOTIFICATION_MESSAGE")
.initialState(notification.STATE_UNSEEN)
.daysToLive(1);
if(status)
{
notificationConfig.caption(captionStatus)
.description(descriptionStatus);
}
else if(responsible)
{
notificationConfig.caption(captionResponsible)
.description(descriptionResponsible);
}
notification.addNotificationWith(notificationConfig);