Script Runner -- how do I pull Created Date information from an issue?

Bryan Karsh
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.
January 13, 2014

Hi,

This is silly, but I am stumped. I am trying to get the created date for an issue. I have a custom Date Picker Field, that needs to be populated by a date that is derived from the Created date plus x number of days based on some logic.

However -- when I try to get the created date, I get an error that I am trying to cast a boolean (see below screenshot).

I am running Jira 5.2.6, and Script Runner 2.1.11

When I look at 5.2.6 API for com.atlassian.jira.issue.IssueImpl, it seems like I should be able to call created -- or getCreated -- and that 'isCreated' is the boolean?

Any tips much appreciated!

2 answers

1 accepted

4 votes
Answer accepted
Henning Tietgens
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.
January 14, 2014

You provided your answer :-) Try issue.getCreated(). Sometimes it's not clear for Groovy which method to call...

Bryan Karsh
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.
January 14, 2014

Ha! You're right. I could have sworn I tried that as well. Maybe I had some weird caching goin on. Anyway, this works:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue

myissue = "TESTPMGMT-17"
IssueManager issueManager = ComponentManager.getInstance().getIssueManager()

Issue issue = issueManager.getIssueObject("$myissue")

Date Created = issue.getCreated()

I will mark your answer as correct. Thanks for the help!

JamieA
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.
January 14, 2014

yep, ".created" will call isCreated() in preference to getCreated(). IIRC this is the only place where I've had this problem.

0 votes
Manuel Santiago Risquez May 11, 2020

Me pasa una cosa como puedo restar dos campos de fecha por ejemplo he creado un custom field con valor 25/05/2019 y quiero restarle la fecha de hoy  menos 25/05/2019.

si me pueden ayudar por favor.

muchas gracias.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.UserPropertyManager

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManafer = ComponentAccessor.getIssueManager()
def userManager = (UserManager) ComponentAccessor.getUserManager()

MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject('GDI-323')//Cojemos la issue hija


//issue = ComponentAccessor.getIssueManager().getIssueObject()//Accedemos a los componentes de la issue

CustomField cfechaSolicitud = customFieldManager.getCustomFieldObjects(issue).find { it.name == "Fecha de Solicitud" }//Buscamos la label Dato1 dentro del padre

log.error("la fecha de solicitud es: " +cfechaSolicitud)

def valuefechaSolicutud =(String)issue.getCustomFieldValue(cfechaSolicitud)//Cojemos el valor del padre en la etiqueta dato1Origen

def value2=valuefechaSolicutud.substring(8,10)
log.error("El valor de la fecha de solicitud es: " +value2)

def hoy = new Date()

def valuefechaHoy=hoy.dateString.substring(2,4)
log.error("El valor de la fecha de hoy es: " +valuefechaHoy)

 

CustomField CfTMO = customFieldManager.getCustomFieldObjectByName("TMO")//identificar el campo para el seteo
log.error("El campo TMO se tiene que identificar asi: se debe identifcar asi para el seteo: " +CfTMO)

def tiempoEntreEllas=valuefechaHoy - value2

log.error("Fecha entre ellas: " +tiempoEntreEllas)

//issue.setCustomFieldValue(tiempoEntreEllas,CfTMO)
//issueManafer.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

Suggest an answer

Log in or Sign up to answer