You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
Our Current Scenario:
This field can be updated at any time and is not tied to a workflow as a result.
We looked at behaviors, but it appears that listeners may be the best place to do this. I am new to groovy and unsure of what to place into our script to create a child link between 2 issues when that custom field is changed.
Any help would be appreciated.
I think something like this (untested) should work:
Edit: I got creative and if you don't have much scripting experience it will be easier for you
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.changehistory.ChangeHistoryItem
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.Field
import com.atlassian.jira.issue.link.IssueLinkType
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.scriptrunner.parameters.annotation.FieldPicker
import com.onresolve.scriptrunner.parameters.annotation.ShortTextInput
import com.onresolve.scriptrunner.parameters.annotation.UserPicker
@FieldPicker(label = "Issue Picker", description = "The Issue Picker field the user is selecting from")
Field issuePicker
@ShortTextInput(label = "LinkType Name", description = "The Link Type name you want to create between the two issues. Eg: Child Of")
String linkTypeName
@UserPicker(label = "Admin User", description = "User that have edit permission in all projects")
ApplicationUser admin
Issue issueFrom = event.getIssue()
CustomField cfIssuePicker = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(issuePicker.getId())
if (cfIssuePicker.getName() in getFieldsChanged()*.getField()) {
Issue issueTo = cfIssuePicker.getValue(issueFrom) as Issue
IssueLinkType issueLinkType = ComponentAccessor.getComponent(IssueLinkTypeManager).getIssueLinkTypesByName(linkTypeName)?.first()
if (issueLinkType)
ComponentAccessor.getIssueLinkManager().createIssueLink(issueFrom.getId(), issueTo.getId(), issueLinkType.getId(), 1L, admin)
}
List<ChangeHistoryItem> getFieldsChanged() {
return ComponentAccessor.getChangeHistoryManager().getAllChangeItems(event.getIssue())?.findAll {
it?.getChangeGroupId() == event.getChangeLog()?.id
}
}
Regards
You should pick "Update Issue" event in the scriptrunner listener list. It may not work if the issue is edited in a transition screen.
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.
@Alejandro Suárez _Tecnofor_ this has been working great! I wanted to see if you had any additional insight into what changes we could make to this script to also copy values from the outward linked issue into the issue that had a change on the field.
Example:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Stephen Higgins this is the code:
Just to clarify, the values of that fields always will be copied to the linked issue, that means that if the values in the original issue are null, then it will erase the values in the linked issue (if there is any).
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.changehistory.ChangeHistoryItem
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.Field
import com.atlassian.jira.issue.link.IssueLinkType
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.scriptrunner.parameters.annotation.FieldPicker
import com.onresolve.scriptrunner.parameters.annotation.ShortTextInput
import com.onresolve.scriptrunner.parameters.annotation.UserPicker
@FieldPicker(label = "Senior Director of Client Services", description = "Senior Director of Client Services Field")
Field seniorDirectorField
@FieldPicker(label = "Director of Client Services", description = "Director of Client Services Field")
Field directorClientField
@FieldPicker(label = "Issue Picker", description = "The Issue Picker field the user is selecting from")
Field issuePicker
@ShortTextInput(label = "LinkType Name", description = "The Link Type name you want to create between the two issues. Eg: Child Of")
String linkTypeName
@UserPicker(label = "Admin User", description = "User that have edit permission in all projects")
ApplicationUser admin
Issue issueFrom = event.getIssue()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField cfIssuePicker = customFieldManager.getCustomFieldObject(issuePicker.getId())
if (cfIssuePicker.getName() in getFieldsChanged()*.getField()) {
MutableIssue issueTo = cfIssuePicker.getValue(issueFrom) as MutableIssue
IssueLinkType issueLinkType = ComponentAccessor.getComponent(IssueLinkTypeManager).getIssueLinkTypesByName(linkTypeName)?.first()
if (issueLinkType) {
ComponentAccessor.getIssueLinkManager().createIssueLink(issueFrom.getId(), issueTo.getId(), issueLinkType.getId(), 1L, admin)
CustomField cfSeniorDirector = customFieldManager.getCustomFieldObject(seniorDirectorField.getId())
CustomField cfDirectorClient = customFieldManager.getCustomFieldObject(directorClientField.getId())
issueTo.setCustomFieldValue(cfSeniorDirector, issueFrom.getCustomFieldValue(cfSeniorDirector))
issueTo.setCustomFieldValue(cfDirectorClient, issueFrom.getCustomFieldValue(cfDirectorClient))
ComponentAccessor.getIssueManager().updateIssue(admin, issueTo, EventDispatchOption.ISSUE_UPDATED, false)
}
}
List<ChangeHistoryItem> getFieldsChanged() {
return ComponentAccessor.getChangeHistoryManager().getAllChangeItems(event.getIssue())?.findAll {
it?.getChangeGroupId() == event.getChangeLog()?.id
}
}
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.
Back in April of last year one of the major product announcements from Opsgenie was the launch of the Incident investigation view which created a deep connection between Bitbucket and Opsgenie, empow...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.