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,412,291
Community Members
 
Community Events
169
Community Groups

How to write a number-customfield in a transition (script-runner)

Hi there

I would like to calculate some number-fields in a post function with a custom script post-function (inline script) from script-runner. 

As i heard from other companies that scripted fields slow down the performance, i would like to update the fields with a transition and calculate the summary in the postfunction.

At the end i have to summarize about 10 number-fields. No i try to catch the value from one field an put it in the targetfield.  I get no error, but the targetfield is not updated.

I have search quite a lot, but there must be something with the setCustomFieldValue. 

Can anyone help me to find and solve the problem or does anyone have a suggestion how i could solve this task in a better way?

Thanks a lot for your help.
Roman

 

// Imports
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.component.ComponentAccessor

// declare Logger
Logger log = Logger.getLogger("css.workflow.project.update")
log.setLevel(Level.INFO)

// declare Destination-Field
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def fBusinessValueCalcld = customFieldManager.getCustomFieldObjectByName("Business Value Calculated")
log.info("Destination Field ID: ${fBusinessValueCalcld}")

// declare Field to read values (Numberr-Fields) - Total 10 Fields
def f1 = customFieldManager.getCustomFieldObjectByName("Value Strategiebezug")
def f1Value = issue.getCustomFieldValue(f1)?:null

// Logging Fields and Values
log.info("Field f1: ${f1.getFieldName()}")
log.info("Field Value f1: ${f1Value}")


if (f1) {
// set the value to the destinatio-field
issue.setCustomFieldValue(fBusinessValueCalcld, f1Value)
}

 

2 answers

Hi @Tarun Sapra 

Thanks for your Info and for your links. I'm going to check this.

Hello @Tarun Sapra 

I've change to the other function. But unfortunatly, i get no content in the field.
Now my code looks like following. Every log-statement is logged out with the correct data. Is there a further way to find out why?

Thanks again for your help.
Roman

 

// Imports
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

// declare Logger
Logger log = Logger.getLogger("css.workflow.project.update")
log.setLevel(Level.INFO)

// declare Destination-Field
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def fBusinessValueCalcld = customFieldManager.getCustomFieldObject("customfield_17221")
def fBusinessValueCalcOldValue = issue.getCustomFieldValue(fBusinessValueCalcld)

log.info("Destination Field ID: ${fBusinessValueCalcld}")
log.info("Destination Field Name: ${fBusinessValueCalcld.getFieldName()}")
log.info("Destination Field Wert: ${fBusinessValueCalcOldValue}")

// declare Field to read values (Numberr-Fields) - Total 10 Fields
// def f1 = customFieldManager.getCustomFieldObjectByName("Value Strategiebezug")
def f1 = customFieldManager.getCustomFieldObject("customfield_17212")
def f1Value = issue.getCustomFieldValue(f1)?:null

// Logging Fields and Values
log.info("Field f1: ${f1.getFieldName()}")
log.info("Field Value f1: ${f1Value}")

def result = f1Value
log.info("Neuer Zielwert: ${result}")


// Fieldlayout
def FieldLayoutItem = ComponentAccessor.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem(fBusinessValueCalcld);


// if Fields exists
if (fBusinessValueCalcld && f1 && result) {
log.info("Everything is ok ant the field should be updated")
def changeHolder = new DefaultIssueChangeHolder()

// set the value to the destinatio-field
fBusinessValueCalcld.updateValue(FieldLayoutItem, issue, new ModifiedValue(fBusinessValueCalcOldValue, result), changeHolder)

}

Suggest an answer

Log in or Sign up to answer