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)
}
Hi @Tarun Sapra
Thanks for your Info and for your links. I'm going to check this.
Hello @Roman Joss
Don't use setCustomField
Sets a custom field value on this Issue Object, but does not write it to the database. This is highly misleading.
Instead use "updateValue" method on custom field object.
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.
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)
}
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.