Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

calculated field Scriptrunner

Olivier MAZEN
Contributor
June 8, 2018

Hello there,

 

I am getting an issue on a calculated field.

 

The value return on my view screen is $value.longValue().

When i trace my value in log field, i get the rigth format (a number)

 

my calculated field get the number of day between the created date of an issue and the date of today.

 

I am missing something but i dont get it

 

here is the code i used:

// Bibliothéque
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import java.util.Date.*;

import org.apache.log4j.Category
//definition of logs
Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)


log.debug("Dans mon script FIeld")


// je recupére mon context.
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

// je récupére le champs Date Dépose Ticket et sa valeur
def cfdatecreationvalue = issue.getCreated() as Date

log.debug("cfdatecreationvalue: " + cfdatecreationvalue)

//je crée la date du jour
Date today = new Date()

 

def compteur = 0

log.debug("compteur: " + compteur)

log.debug("today: " + today)

// ma formule de calcule
if(cfdatecreationvalue == null || cfdatecreationvalue == 0)
{
log.debug("IF 1")
compteur = 0
}
else if (today != cfdatecreationvalue)
{
log.debug("IF 2")
compteur = today - cfdatecreationvalue
}

log.debug("final compteur: " + compteur)
return compteur

 

If you find out where i am doing something wrong please let me know :)

 

regards,

 

Olivier

 

1 answer

1 accepted

1 vote
Answer accepted
Alexey Matveev
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.
June 8, 2018

Hello,

What is exactly the error? The value has a different format on the screen?

Olivier MAZEN
Contributor
June 8, 2018

Hello,

 

i get $value.longValue(). on the screen and 1 in the log.

 

 Capture.JPG

 

Like Deleted user likes this
Alexey Matveev
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.
June 8, 2018

Just return $value. Without the longValue() part.

Olivier MAZEN
Contributor
June 8, 2018

heu i am not sure you get it

 

i return my value like this:

compteur = today - cfdatecreationvalue

Return compteur

and i get 

$value.longValue() on IHM

Alexey Matveev
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.
June 8, 2018

What is the template for your scripted field?

Olivier MAZEN
Contributor
June 11, 2018

Hello,

 

i have try both template number field and text filed multi line.

 

No change, my screen view always $value.longValue() is displayed.  

Olivier MAZEN
Contributor
June 11, 2018

Hello,

 

i found out my probleme.

 

Thx once again for the support :)

Shlomi Perets
Contributor
August 29, 2018

Can you publish what was the problem?

Olivier MAZEN
Contributor
August 29, 2018

hi,

 

i have to switch the template of the scripted field  from Number Field to Text Field (multi-line).

 

Olivier

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events