Hello Atlassian Community, I'm asking you today because I'm stuck on the script of a scripted field (I'm using ScriptRunner).
Here is my usecase :
A "Start date" (Date Picker) field is diplayed on my ticket and I have created a "Week Number" scripted field, also displayed on this ticket.
I would like to retrieve format "W25 2022" on Week Number field based on the Start date.
I have started some script on the Week Number field :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import static java.util.Calendar.WEEK_OF_YEAR
import static java.util.Calendar.YEAR
import java.sql.Timestamp
Issue issue = issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// get Start date custom field
def date1 = customFieldManager.getCustomFieldObjectByName("Start date")
// get Start date value
def date1Value = issue.getCustomFieldValue(date1) as Date
// create Week Number custom field
def date2 = Calendar.getInstance()
// copy in Week Number the Start date value
date2.setTime(date1Value)
// transform date2 into format "WeekWW YYYY"
return (issue.getCustomFieldValue(date2) as Timestamp)?.toCalendar().get("WEEK_OF_YEAR", "YEAR")
If anyone has any idea on this topic, it will be appreciated :)
if you just need a value of format WeekWW YYYY, you can use this code
def date1 = customFieldManager.getCustomFieldObjectByName("Start date")
// get Start date value
def date1Value = issue.getCustomFieldValue(date1)
Calendar cal = Calendar.getInstance()
cal.setTime(date1Value)
return ("Week" + cal.get(Calendar.WEEK_OF_YEAR) + cal.get(Calendar.YEAR))
Hello @Tuncay Senturk
I didn't expect such a quick answer !
I have implemented your code and it works perfectly, that's exactly what I wanted to do !
Thanks a lot !!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm glad that it worked! :D
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.