Hi,
I have a custom calculated field (Turn Around Time) which i use across different issue types and is calculated differently depending on which issue type it is. I have a javascript function to calculate turn around excluding weekends and i am wanting to add this to post function so the turn around is calculated when issue resolved.
I am having trouble finding out how to set the value of the custom field. I am also not sure if this script will even work (noob to javascript and how it works with JIRA's post function)
Is this right?
<script type="text/javascript">
//script calculator !
if (issue.get("issuetype") == "Specials") {
issue.getelementbyid("customfield_10264").val(calculateworkingdays(issue.get("resolutiondate").getDate(), issue.get("customfield_10007").getDate()))
} else {
issue.getelementbyid("customfield_10264").val(calculateworkingdays(issue.get("resolutiondate").getDate(), issue.get("customfield_10002").getDate()))
}
// function
function calculateWorkingdays(stDate,enDate) {
var startDateYear = stDate.getFullYear();
var startDateMonth = stDate.getMonth();
var startDateDat = stDate.getDate();
var startDateDay = stDate.getDay();
var endDateYear = enDate.getFullYear();
var endDateMonth = enDate.getMonth();
var endDateDat = enDate.getDate();
var endDateDay = enDate.getDay();
ssDate = new Date(startDateYear,startDateMonth,startDateDat);
eeDate = new Date(endDateYear,endDateMonth,endDateDat);
if (ssDate > eeDate) {
workingDays = 0;
return workingDays;
}
workingDays = 0;
while (ssDate <= eeDate) {
if(ssDate.getDay()!=0 && ssDate.getDay()!=6) {
workingDays++;
}
ssDate=new Date(ssDate.valueOf()+86400000);
}
// to make days between *** exclusive *** of start/end dates uncomment the three lines below
//if ((startDateDay != 0) && (startDateDay != 6)) { workingDays -- }
//if ((endDateDay != 0) && (endDateDay != 6)) { workingDays -- }
//if (workingDays <0) {workingDays = 0}
return workingDays;
}
</script>