// // Integrity Manager PRE-Event Trigger //
// Update timesheet item's time entries based on field changes in a related Task Item. //
//
// @param Field:relationship Timesheet_Field_Name
// Name of the relationship field that is used to link a (public) Task to a (private) Timesheet.
// Users without TimeSheet permisison should not be able to see this field.
//
// @param Field:float Duration_Field_Name
// Name of the float field in hte Task that contains the daily spent effort (max 24.0) which is
// to be set as a time entry in the related TimeSheet for the current user.
// Users without TimeSheet permisison should not be able to see this field.
//
// For debugging purposes
function print(s)
{
java.lang.System.out.println(s);
}
function abort(s)
{
eb.abortScript(s, true);
}
function noPost(s)
{
eb.abortScript(s, false);
}
var eb = bsf.lookupBean("siEnvironmentBean");
var sb = bsf.lookupBean("imServerBean");
var params = bsf.lookupBean("parametersBean");
var delta = bsf.lookupBean("imIssueDeltaBean");
eb.setMessageCategory("DEBUG");
logging = eb.messageCheck();
debugging = eb.messageCheck(10);
if (eb.getEventName() != "Issue.changed.pre"){
abort(eb.getMessage("ERROR_SCRIPT_CONDITION"));
}
if (debugging) {
eb.print("---------------begin---------------");
}
var relationshipField = params.getParameter("Timesheet_Field_Name");
var durationField = params.getParameter("Duration_Field_Name");
// Check if we have the linked issue
var relatedTimesheets;
if (relationshipField != null && relationshipField.length() > 0){
relatedTimesheets = delta.getRelatedIssues(relationshipField);
}
else{
relatedTimesheets = delta.getRelatedIssues();
}
// store current user for later use
var currentUser = delta.getCurrentUser();
// get the value to set from the delta
var duration = delta.getNewFieldValue(durationField)
// create a date (utc midnight) reflecting the value of today and the environment's timezone offset.
var now = new Date();
var currentDate = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
currentDate.setHours(0,0,0,0); // eliminate the time
//valid format for the API call is "MMM d, yyyy"
var options = { month: 'short', day: 'numeric' };
var currentDateStr = currentDate.toLocaleDateString('en-EN', options);
// use StringBuilder to create AIP command parameter
var actionSB = new java.lang.StringBuilder();
actionSB.append("