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

Script is not working, throwing an error

Hi Team,

I have implemented a script for calculating Number Of Weeks:

import com.atlassian.jira.component.ComponentAccessor

 

def dateFieldObject = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("Start Date")[0]

def dateFieldObject2 = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("End Date")[0]

 

def dateValue= issue.getCustomFieldValue(dateFieldObject) as Date

def dateValue2= issue.getCustomFieldValue(dateFieldObject2) as Date

def now = new Date()

 

def diffdate

 

// if "End Date" is reached or exceeded, which means "now" is later than "End Date"

if (now.after(dateValue2)){

    // End Date - Start Date

    diffdate = dateValue2 - dateValue

} else {  // if now is before or equal to "End Date"

    // End Date - now

                diffdate = dateValue2 - now

}

 

if (diffdate) {

    double noofweeks = diffdate/7

    double roundNoOfWeeks = Math.round(noofweeks)

    int value = (int) roundNoOfWeeks;

                return value

}

 

but getting attached error, please kindly check and give me some solution where I am doing error.PNGwrong.

 

2 answers

0 votes

Hi @neeta jain 

 

Take a look at this documentation, you will find some good stuff to begin wih

https://www.adaptavist.com/blog/effortlessly-calculate-dates-and-times-with-the-adaptavist-library-in-jiranew-blog-post

hope this helps

0 votes

The error message says line 6 is failing.  I think the code on that line is the one trying to get a date from the "start date" field.  A null pointer error here means that there is no data in something you are passing into a method on that line.

Either the field does not exist for this issue, or the data in it is not a date, or is empty.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS

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