Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,556,538
Community Members
 
Community Events
184
Community Groups

Script need to be modified

Hi Team,

I have implemented a script to calculate Number if weeks from start date to end date, see below:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import java.util.Date.*
import static java.lang.Math.*
import java.sql.Timestamp

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateFieldObject= customFieldManager.getCustomFieldObject('customfield_18880');

def dateFieldObject2= customFieldManager.getCustomFieldObject('customfield_12110');

if(issue.getCustomFieldValue(dateFieldObject) && issue.getCustomFieldValue(dateFieldObject2)) {
def dateValue= issue.getCustomFieldValue(dateFieldObject) as Date
def dateValue2= issue.getCustomFieldValue(dateFieldObject2) as Date

def diffdate = dateValue - dateValue2
double noofweeks = diffdate/7

double roundNoOfWeeks = Math.round(noofweeks)

int value = (int) roundNoOfWeeks;

return value

}

 

Now I need some modification in it, 

So the current calculation is (Today - Start date), then once reach the End date, the calculation will be (End date - Start date).

So need Number of weeks =  Today's date(system date) -Start Date

and 

If one issue reached to end date then Number of weeks = End Date-Start date.

 

Kindly please help me to modify this, I am not aware how to get the system date in the script.

 

Regards,

Neeta Jain

1 answer

3 votes
Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Oct 09, 2020

Hi @neeta jain 

You can can current date/time using this code.

Date dateObj = new Date()
def timestamp = new SimpleDateFormat('dd-MM-yyyy--HH-mm').format(dateObj)

Also please look for scripts on https://library.adaptavist.com/ you will find plenty of examples.

Ravi 

Hi Ravi,

After adding above 2 line code, its giving an error that simpledateformat is not available?

Can you please suggest the solution for it.

 

Regards,

Neeta Jain

Like Ravi Sagar _Sparxsys_ likes this
Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Oct 14, 2020

Hi @neeta jain 

You need to add this line on top as well.

import java.text.SimpleDateFormat

Ravi

Thanks Ravi.

But when i return the value for timestamp, it just giving 14(today's date)

I wanted to apply formula for system date - end date.

So how would I get the exact date format, so that i can apply the formula.

 

Regards,

Neeta Jain

Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Oct 14, 2020

You can modify the format if you want by modifying the argument

'dd-MM-yyyy--HH-mm'

Did you take a look at the example scripts on library? Take a look at this script to understand how to work with dates.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events