Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,294,103
Community Members
 
Community Events
165
Community Groups

How to manage a scripted field based on a Date Picker field ?

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 :)

1 answer

1 accepted

2 votes
Answer accepted
Tuncay Senturk Community Leader Jun 23, 2022

Hi @support for vo 

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 !!

Tuncay Senturk Community Leader Jun 23, 2022

I'm glad that it worked! :D 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
Community showcase
Published in Jira Software

Upcoming changes to epic fields in company-managed projects

👋 Hi there Jira Community! A few months ago we shared with you plans around renaming epics in your company-managed projects. As part of these changes, we highlighted upcoming changes to epics on...

14,169 views 34 44
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you