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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,270
Community Members
 
Community Events
184
Community Groups

script runner calculated field

Edited

Hi all,

Does anyone can help me. I'm quite new in scripting...

I need to get a value from a calculated field (number field) and multiply it by 250

 

I'm using this for a field with the value "5":

import com.atlassian.jira.component.ComponentAccessor;
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10102");
def value = (String)issue.getCustomFieldValue(customField);

return value * 250

 

But the result is:

5.05

 

tks for any help

 

2 answers

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Mar 12, 2020

Try to convert your value to a double before making math operation:

return value.toDouble() * 250

Or get it as a double in the first place

def value = (Double)issue.getCustomFieldValue(customField);

Tks Peter.

this works fine

return value.toDouble() * 250

Buenas Tardes, 

alguien me puede ayudar?.

Estaba creando un script para ponerlo como condicion en una transaccion, consiste en que si el customfield (Fecha), es menor que el dia 25 del mes actual me deje validar la issue sino no, el problema es que lo meto en conditions se me ejecuta pero no me hace nada.

 

Script: 

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.Issue
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import java.sql.Timestamp
import com.atlassian.jira.issue.MutableIssue
import java.util.Date
import java.text.SimpleDateFormat
import java.text.DateFormat


//MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject('MANI-8')
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManafer = ComponentAccessor.getIssueManager()
def userManager = (UserManager) ComponentAccessor.getUserManager()

CustomField cfFecha = customFieldManager.getCustomFieldObjectByName("Fecha")

def valorFecha = (String)issue.getCustomFieldValue(cfFecha)
def diaCustomField=valorFecha.substring(8,10)
def mesCustomField=valorFecha.substring(5,7)

def currentDate = new Date ()
def fechaActual=currentDate.dateString
def mesActual= fechaActual.substring(3,5)
def diaActual=currentDate.date.toString()

if (diaActual <= '25' && diaCustomField <= '25' && mesCustomField==mesActual || diaCustomField >= '25' && mesCustomField != mesActual ) {
return true
}
else {
return false
}

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 30, 2020

While it may work, I don't think it's a good idea to use<= on a string value, I'd recommend you work with integers.

You don't need to convert your date to sting then parse it with substring, just use the built-in date object methods like getDate() and getMonth()

For example

def currentDate = new Date().minus(10)
def valorFecha = issue.getCustomFieldValue(cfFecha)

return (currentDate.date <= 25 && valorFecha.date <= 25 && currentDate.month == valorFecha.month || valorFecha.date >=25 && currentDate.month != valorFecha.month)

Here are all the different permutation with example dates for the logic statement:

today=30Apr, Cf = 30Apr > false (same month /no date<25)
today=30Apr, Cf = 15Apr > false (same month /cf date<25)
today=15Apr, Cf = 30Apr > false (same month /today date<25)
today=15Apr, Cf = 15Apr > true  (same month /both dates<25)

today=30Apr, Cf = 15May > false  (different month /cf date<25)
today=15Apr, Cf = 30Apr > true (different month /cf date !<25)
today=15Apr, Cf = 15May > false (different month /both dates <25) 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events