I am trying to create custom scripted field using script runner to calculate the end dates
But got stuck here.
below is my code
import com.atlassian.jira.issue.MutableIssue import java.sql.Timestamp; MutableIssue myIssue = issue; def dateField = getCustomfieldValue("Date") Calendar dateField = Calendar.getInstance() def numberfield = getcustomFieldValue("Days") def number = numberfield?.intValue() if number (!number || !dateField) return dateField.add(Calendar.DATE, number) while ([Calendar.SATURDAY, Calendar.SUNDAY].contains(dateField.get(Calendar.DAY_OF_WEEK))) { def dateField.add(Calendar.DATE,number) } def result = new Timestamp(dateField.gettime()) return new Date(result.gettime())
Hey Amar,
I thought that what you wanted was related to your last question here (https://answers.atlassian.com/questions/32023338), if not please let me know in order to delete it. You can try this part of code (I left in purpose the variable types). Of course there is room for optimisation.
import java.sql.Timestamp Timestamp dateField = (Timestamp) getCustomFieldValue("DateCF") long numberField = (long) getCustomFieldValue("NumberCF") if (numberField == null) return int number = numberField.intValue() if (dateField) { Date result = dateField; Date newDate = new Date(result.getTime()) int i = 0 ; while (i < number) { result = result + 1 newDate = new Date(result.getTime()) if (newDate[Calendar.DAY_OF_WEEK] == Calendar.SATURDAY || newDate[Calendar.DAY_OF_WEEK] == Calendar.SUNDAY) { number ++; } i ++; } return newDate } return
Regards,
Thanos
Amar, I suppose what you mean is to learn how to write scripts. There is plenty of documentation in the web. Especially for the script runner there are a lot of examples in the documentation https://scriptrunner.adaptavist.com/latest/jira/quickstart.html. What I can advise you is to keep practicing. Regards, Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.