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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Number of weeks calculated(scripted field)

Hi Team,

I have implemented one script for calculating Number Of Weeks, 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 the user need some modification in it,

as

Number Of weeks(Calculated)= Today's date (NOW)- End Date ?

And if End date is reached, then (End date – Start date).

 

I have tried but not able to get the Today's date from the script.

Kindly please help me out to reach the modifications in the script.

 

Regards,

Neeta Jain

1 answer

0 votes
Leo Community Leader Oct 23, 2020

Hi @neeta jain

You can get current date in script using below snippet

today = new java.sql.Timestamp(new Date().getTime())

using this you can compare today's date with end date and do the calculation

 

BR,

Leo 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Jira Cloud Performance Improvements

Hello everyone, I am a product manager in the Jira Cloud team focused on making sure our customers have a delightful experience using our products. Towards that goal, one of the areas which is extr...

175 views 2 9
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