Hi I have a problem setting new value to a custom field date time picker. The requiremement is to add X working days to a specific custom date field. Can anyone help me on this? Any sugestion would be of great help.
Below is my post function code that supposed to work but it does not work as I expected:
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.MutableIssue;
import java.sql.Timestamp;
import com.atlassian.jira.issue.util.IssueChangeHolder
// initializing the priority
def Urgent = 5;
def High = 20;
def Medium = 30;
def None = 0;
private GregorianCalendar getDate(double roll)
{
Calendar cal = Calendar.getInstance();
cal.setFirstDayOfWeek(Calendar.MONDAY);
cal.set(Calendar.HOUR_OF_DAY,0);
cal.set(Calendar.MINUTE,0);
cal.set(Calendar.SECOND,0);
cal.set(Calendar.MILLISECOND,0);
int numNonBusinessDays = 0;
if(cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
numNonBusinessDays++;
}
cal.add(Calendar.DATE, 1);
}
if(numNonBusinessDays > 0) {
cal.add(Calendar.DATE, numNonBusinessDays);
}
return cal;
}
key = issue.getKey();
def priority = mutableIssue.getPriority().getString("name");
IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
MutableIssue issue = issueManager.getIssueObject(key);
customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
GregorianCalendar cal;
if(priority.equals("1-Urgent")) {
cal = getDate(Urgent);
}
else if(priority.equals("2-High")) {
cal = getDate(High);
}
else if(priority.equals("3-Medium")) {
cal = getDate(Medium);
}
// get the Date value from Date Full Packed Receive custom field
dateFPR = customFieldManager.getCustomFieldObjectByName("Date Full Pack Received");
dateFPRValue = issue.getCustomFieldValue(dateFPR);
// get the Date value from SLA Date custom field
dateSLA = customFieldManager.getCustomFieldObjectByName("SLA Date");
dateSLAValue = issue.getCustomFieldValue(dateSLA);
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
Timestamp dueDate = new Timestamp(cal.getTimeInMillis());
dateSLA.updateValue(null, issue, new ModifiedValue(dateSLAValue, dueDate), changeHolder);