Hi,
I've got problem with scripts in post function on "Create" transition.
I've got project X and project Y. In project X I'm creating linked-issue to project Y, and in Y I've got this post function (create transition):
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Level
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.issue.fields.FieldManager
import com.atlassian.jira.issue.RendererManager
import com.atlassian.jira.issue.fields.NavigableField
log.setLevel(Level.DEBUG)
//Get necessary managers
def cfm = ComponentAccessor.customFieldManager
def linkManager = ComponentAccessor.issueLinkManager
def PoczKeyValue = issue.key
log.info("PoczKeyValue: " + PoczKeyValue)
//def cfPoczKey = cfm.getCustomFieldObjectByName("Numer poczekalnia") // ID: 12418
def cfPoczKey = cfm.getCustomFieldObject(12418L)
log.info("cfPoczKey: " + cfPoczKey)
linkManager.getOutwardLinks(issue.id).each
{
log.info("each test")
it ->
((MutableIssue) it).setCustomFieldValue(cfPoczKey, PoczKeyValue)
ComponentAccessor.getIssueManager().updateIssue(event.user, ((MutableIssue) it), EventDispatchOption.DO_NOT_DISPATCH, false)
}
I've got problem from this line:
((MutableIssue) it).setCustomFieldValue(cfPoczKey, PoczKeyValue)
I'ld like to update cfPoczKey in linked-issue, but I've error:
2019-08-22 19:29:48,535 INFO [workflow.ScriptWorkflowFunction]: PoczKeyValue: POCZ-98 2019-08-22 19:29:48,536 INFO [workflow.ScriptWorkflowFunction]: cfPoczKey: Numer poczekalnia 2019-08-22 19:29:48,541 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2019-08-22 19:29:48,541 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: POCZ-98, actionId: 1, file: <inline script> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.atlassian.jira.issue.link.IssueLinkImpl@187a1b6d[id=15221,sourceId=53714,destinationId=32226,issueLinkType=10200]' with class 'com.atlassian.jira.issue.link.IssueLinkImpl' to class 'com.atlassian.jira.issue.MutableIssue' at Script348$_run_closure1.doCall(Script348.groovy:28) at Script348.run(Script348.groovy:24)
Hi @Rafał Baczyński ,
(MutableIssue) it
it is issuelink object, but you are trying to cast it to Mutable issue. so it it throwing error.
Please refer below link Adaptvist library, this will help you.
https://library.adaptavist.com/entity/update-a-field-across-all-the-linked-issues
Hi :)
Ok, I used this information, but it's still not working :(
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Level
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.issue.fields.FieldManager
import com.atlassian.jira.issue.RendererManager
import com.atlassian.jira.issue.fields.NavigableField
log.setLevel(Level.DEBUG)
//Get necessary managers
def cfm = ComponentAccessor.customFieldManager
def linkManager = ComponentAccessor.issueLinkManager
def PoczKeyValue = issue.key
log.info("PoczKeyValue: " + PoczKeyValue)
//def cfPoczKey = cfm.getCustomFieldObjectByName("Numer poczekalnia") // ID: 12418
def cfPoczKey = cfm.getCustomFieldObject(12418L)
log.info("cfPoczKey: " + cfPoczKey)
def links = linkManager.getOutwardLinks(issue.id)
log.info("Links: "+links)
links.each
{
def linkedIssue = it.destinationObject
log.info("linkedIssue: "+linkedIssue)
((MutableIssue) linkedIssue).setCustomFieldValue(cfPoczKey, PoczKeyValue)
ComponentAccessor.getIssueManager().updateIssue(event.user, ((MutableIssue) it), EventDispatchOption.DO_NOT_DISPATCH, false)
}
Error:
2019-08-22 20:41:01,294 INFO [workflow.ScriptWorkflowFunction]: PoczKeyValue: POCZ-101 2019-08-22 20:41:01,294 INFO [workflow.ScriptWorkflowFunction]: cfPoczKey: Numer poczekalnia 2019-08-22 20:41:01,294 INFO [workflow.ScriptWorkflowFunction]: Links: [com.atlassian.jira.issue.link.IssueLinkImpl@6058830[id=15225,sourceId=53718,destinationId=32226,issueLinkType=10200]] 2019-08-22 20:41:01,296 INFO [workflow.ScriptWorkflowFunction]: linkedIssue: PLZAM-4359 2019-08-22 20:41:01,300 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2019-08-22 20:41:01,300 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: POCZ-101, actionId: 1, file: <inline script> groovy.lang.MissingPropertyException: No such property: event for class: Script399 at Script399$_run_closure1.doCall(Script399.groovy:31) at Script399.run(Script399.groovy:26)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, I corrected code and it's ok. Tkank you very much :) Best regards from Poland
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Level
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.issue.fields.FieldManager
import com.atlassian.jira.issue.RendererManager
import com.atlassian.jira.issue.fields.NavigableField
log.setLevel(Level.DEBUG)
//Get necessary managers
def cfm = ComponentAccessor.customFieldManager
def linkManager = ComponentAccessor.issueLinkManager
def PoczKeyValue = issue.key
log.info("PoczKeyValue: " + PoczKeyValue)
//def cfPoczKey = cfm.getCustomFieldObjectByName("Numer poczekalnia") // ID: 12418
def cfPoczKey = cfm.getCustomFieldObject(12418L)
log.info("cfPoczKey: " + cfPoczKey)
def links = linkManager.getOutwardLinks(issue.id)
log.info("Links: "+links)
links.each
{
def linkedIssue = it.destinationObject
log.info("linkedIssue: "+linkedIssue)
def oldValue = linkedIssue.getCustomFieldValue(cfPoczKey)
def newValue = PoczKeyValue
cfPoczKey.updateValue(null, linkedIssue, new ModifiedValue(oldValue, newValue), 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.