How to change a custom subtask field from the parent issue using the scriptrunner?
issue daughter field "Pontos Historia" = issue parent field "Pontos Historia" * 0.25
Was it something like that?
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager ()
def Campo = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Pontos de Historia'}
def changeHolder = new DefaultIssueChangeHolder ()
Campo.updateValue (null, issue, new ModifiedValue (issue.getCustomFieldValue (Campo) * 0.25, changeHolder)
Hi @fabricio.borges welcome on the community. You just need to set it up on subtasks. THe rest of the script looks fine:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
final customFieldName = 'Pontos Historia'
def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjects(issue).find({
it.getFieldName() == customFieldName})
assert customField : "Could not find custom field with name $customFieldName"
def parentIssue = issue.getParentObject()
issue.setCustomFieldValue(customField, parentIssue.getCustomFieldValue(customField) * 0.25)
I have no environment set up to test the script but if it won't work, just let me know and we will fix it.
how to calculate the value in the subtask by multiplying by a fixed number?
Example.:
new ModifiedValue(mutableSubtask.getCustomFieldValue(customField) * 0.25
?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
in this line....
customField.updateValue(null, mutableSubtask, new ModifiedValue(mutableSubtask.getCustomFieldValue(customField) * 0.25, issue.getCustomFieldValue(customField)), new DefaultIssueChangeHolder())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @fabricio.borges it is almost correct, but first parameter of new ModifiedValue is oldValue, and second is newValue. So it should be:
customField.updateValue(null, mutableSubtask, new ModifiedValue(mutableSubtask.getCustomFieldValue(customField), issue.getCustomFieldValue(customField) * 0.25), new DefaultIssueChangeHolder())
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.
It might be only static check error, but compiler can't know what is the type of result of getCustomFieldValue(...). Did you try to run the code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes, but the error below happens.
Número de referência Log's: 53096f08-a15f-498c-858d-b6345cbeec8e
URL do referenciador: http://suporte.maximatech.com.br/browse/TESTEDV-98
java.lang.AssertionError: Could not find custom field with name Pontos Historia. Expression: customField. Values: customField = null
java.lang.AssertionError: Could not find custom field with name Pontos Historia. Expression: customField. Values: customField = null at Script744.run(Script744.groovy:11) [?:?] at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runScriptAndGetContext(ScriptRunnerImpl.groovy:175) [?:?] at com.onresolve.scriptrunner.runner.ScriptRunner$runScriptAndGetContext$6.callCurrent(Unknown Source) [?:?] at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runStringAsScript(ScriptRunnerImpl.groovy:164) [?:?] at com.onresolve.scriptrunner.runner.ScriptRunner$runStringAsScript$7.call(Unknown Source) [?:?] at com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate.doScript(CustomScriptDelegate.groovy:70) [?:?] at com.onresolve.scriptrunner.canned.jira.utils.AdditionalCustomScriptDelegate.super$2$doScript(AdditionalCustomScriptDelegate.groovy) [?:?] at com.onresolve.scriptrunner.canned.jira.utils.AdditionalCustomScriptDelegate.doScript(AdditionalCustomScriptDelegate.groovy:22) [?:?] at com.onresolve.scriptrunner.canned.jira.utils.AdditionalCustomScriptDelegate$doScript.call(Unknown Source) [?:?] at com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils.doAdditional(ConditionUtils.groovy:232) [?:?] at com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils$doAdditional$3.call(Unknown Source) [?:?] at com.onresolve.scriptrunner.canned.jira.utils.AbstractCloneIssue.doScript(AbstractCloneIssue.groovy:221) [?:?] at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CreateSubTask.super$2$doScript(CreateSubTask.groovy) [?:?] at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CreateSubTask.doScript(CreateSubTask.groovy:144) [?:?]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I adjusted script on the beginning of this branch... give it a try, please.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the script below did not give an execution error. However, it did not update the value of the custom field in the subtask.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
final customFieldName = 'Pontos de História'
def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjects(issue).find({
it.getFieldName() == customFieldName})
assert customField : "Could not find custom field with name $customFieldName"
for(def subtask: issue.getSubTaskObjects()){
def mutableSubtask = issueManager.getIssueObject(subtask.id)
customField.updateValue(null, mutableSubtask, new ModifiedValue(mutableSubtask.getCustomFieldValue(customField), issue.getCustomFieldValue(customField) * 0.8), new DefaultIssueChangeHolder())
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you invoking the script as part of the postfunctions? Or how/when do you invoke it?
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.
Ok, I think the code is invoked on new subtask, so data must be copied from parent. I adjusted script. Is it ScriptRunner's postfunction?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, but unfortunately not yet certain. The value of the custom field in the subtask continues to come from the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried to use
issue.setCustomFieldValue
method, so give it a try, otherwise we will have to debug it a little :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
got it here .. Thank you so much!
def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Pontos Historia'}
issue.setCustomFieldValue(cf, sourceIssue.getCustomFieldValue(cf) * 0.8)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ok great :D it is tough to try to programme virtually :D, have a nice weekend :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@fabricio.borges could you accept the answer please? :)
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.