Hi, i have a script that must give me a current time, but instead of this it gives me java.lang.NullPointerException.
script is here:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import java.sql.Timestamp
import static java.lang.Math.*
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("SEREX-2")
def Current_Date= ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Current date")
// get today's date
issue.setCustomFieldValue(Current_Date, new Timestamp((new Date() + 1).time))
Hi @Andrei Lavrinovich .
Try this.
import java.text.SimpleDateFormat
Date date = new SimpleDateFormat('yyyyMMdd')
issue.setCustomFieldValue(Current_Date, date)
I have found something more easily
return new Date()
that give me current date but only in "Text Field" template and not in "Date Time" template. Do you know maybe something similar for date time template?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is the working code.
import java.text.SimpleDateFormat
SimpleDateFormat date1 = new SimpleDateFormat('dd/MMM/yy') //24/Dec/19
SimpleDateFormat date2 = new SimpleDateFormat('dd/MMM/yy h:m a') //24/Dec/19 6:56 AM
def format1 = date1.format(new Date())
def format2 = date2.format(new Date())
log.debug(format1)
log.debug(format2)
It only works if the Customfield Date format is dd/MMM/yy .e.g 24/Dec/19
If the Customfield is DateTime then the format should be dd/MM/yy h:m a e.g 24/Dec/19 6:56 AM
Refer to this page for more information.
https://www.journaldev.com/17899/java-simpledateformat-java-date-format
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.
My first point of call with a null pointer exception is to add logging and identify what is null
import org.apache.log4j.Logger
import
java.util.Date
def log = Logger.getLogger("com.onresolve.scriptrunner.runner.ScriptRunnerImpl")
...
log.info("" + Current_Date)
etc
chances are one of your access has not returned an object
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"return new Date()" give me current date and time, but not in date time template
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.