I want to update the Assignee field from Parent to Subtask. When i update parent assignee field it should update all subtask assignee field.
import com.atlassian.jira.issue.Issue
//import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
Issue issue = event.issue
def cwdUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def currentAssigneeId = issue.getAssigneeId()
log.warn("currentAssigneeId")
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == currentAssigneeId};
log.warn("childChangeItem")
//def currentAssigneeIdValue = change.currentAssigneeIdValue as String
def currentAssigneeIdValue = issue.currentAssigneeIdValue() as String
log.debug "new value is : ${currentAssigneeIdValue} "
if (change) {
//def currentAssigneeIdValue = change.currentAssigneeIdValue as String
// log.debug "new value is : ${currentAssigneeIdValue} "
issue.getSubTaskObjects()?.
findAll { it.issueType.name in ["Sub-task"]
//get only issues that their issue type is Sub-task
def subtask = ComponentAccessor.getIssueManager().getIssueByCurrentKey(it.key)
subtask.setAssigneeId(currentAssigneeIdValue)
log.warn("Assignee----")
ComponentAccessor.getIssueManager().updateIssue(cwdUser, subtask, EventDispatchOption.DO_NOT_DISPATCH, false)
}
}
Please help on this script.
Thanks,
Sai
Hi @Sai Krishna Yadav Challendula
Below is the working script to update sub-task assignee if parent assignee changed (to valid user)
this needs to be placed in Script listener and "Issue Updated" event needs to be mapped for the same
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.event.type.EventDispatchOption;
def issue = event.issue
def assigneeChanged = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "assignee"}
if(assigneeChanged){
def assignee = issue.assignee
if(assignee){
issue.subTaskObjects.each { s ->
MutableIssue sb = s as MutableIssue
sb.setAssignee(assignee)
ComponentAccessor.getIssueManager().updateIssue(assignee, sb, EventDispatchOption.ISSUE_UPDATED, true)
}
}
}
I've tested the same in my sandbox and working as expected
BR,
Leo
No luck with above script. I have tried different script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sai Krishna Yadav Challendula
In your code, there is a line as below:
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == currentAssigneeId};
I am not sure but, can you please try
it.field == "Assignee" rather than it.field == currentAssigneeId ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Tuncay Senturk ,
I have tried it.field == "Assignee" but it doesn't works for me . Please guide me.
Thanks in advance. Appreciate your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How about using it.field == "assignee" , with lowercase "a"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
Issue issue = event.issue
def cwdUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def currentAssigneeId = issue.getAssigneeId()
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "assignee"};
def currentAssigneeIdValue = issue.currentAssigneeIdValue() as String
if (change) {
issue.getSubTaskObjects()?.findAll { it.issueType.name in ["Sub-task"]
def subtask = ComponentAccessor.getIssueManager().getIssueByCurrentKey(it.key)
subtask.setAssigneeId(currentAssigneeIdValue)
ComponentAccessor.getIssueManager().updateIssue(cwdUser, subtask, EventDispatchOption.DO_NOT_DISPATCH, false)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm getting below error. Please refer the logs.
Time (on server): Thu Sep 02 2021 15:07:10 GMT+0530 (India Standard Time)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2021-09-02 11:37:10,045 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2021-09-02 11:37:10,045 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.currentAssigneeIdValue() is applicable for argument types: () values: [] at Script885.run(Script885.groovy:13)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah, of course. I did not change that part of your code.
I think below will work, bear in mind that I haven't run the codes, I am just trying to help you by coding in this window, sorry if you encounter any errors.
Issue issue = event.issue
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "assignee"};
if (change) {
issue.getSubTaskObjects()?.findAll { it.issueType.name in ["Sub-task"]
def subtask = ComponentAccessor.getIssueManager().getIssueByCurrentKey(it.key)
subtask.setAssigneeId(currentAssigneeIdValue)
ComponentAccessor.getIssueManager().updateIssue(issue.assignee, subtask, EventDispatchOption.DO_NOT_DISPATCH, false)
}
}
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.
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.
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.
I think you haven't checked my latest script. I already removed that part, you shouldn't get that error.
Can you try this one below?
Issue issue = event.issue
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "assignee"};
if (change) {
issue.getSubTaskObjects()?.findAll { it.issueType.name in ["Sub-task"]}.each {
def subtask = ComponentAccessor.getIssueManager().getIssueByCurrentKey(it.key)
subtask.setAssigneeId(currentAssigneeIdValue)
ComponentAccessor.getIssueManager().updateIssue(issue.assignee, subtask, EventDispatchOption.DO_NOT_DISPATCH, false)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you get any error, please paste it rather than saying above, as there are lots of comments and it became hard to track.
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.
Hi @Tuncay Senturk ,
I want to update the Component's field from Parent to Subtask. When I update parent Component's field my Subtask Component fields gets change using Script Can you help me ???
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.