Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Good afternoon. It is not possible to implement a script that, when creating a request on a custom portal, creates a certain relationship based on the completed tasks from the multiple issue pikers field.
The result of what I tried, alas, does not work.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.Issue
final def linkName = "мероприятия"
def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def customField = ComponentAccessor.customFieldManager.getCustomFieldObject(14020)
def linkType = issueLinkTypeManager.issueLinkTypes.find{ it.name == linkName }
def story = issue.getCustomFieldValue(customField) as Issue
if (story) {
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
ComponentAccessor.issueLinkManager.createIssueLink(story.id, issue.id, linkType.id, 0L, user)
}
Your request is not exactly clear but from what I read on your script. You are probably using a post function on a create transition.
1. Have you moved your post function order to be after "Creates the issue originally."?
2. You might want to use doAfterCreate {} closure too if you are using "clone an issue, and links". Try:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.Issue
final def linkName = "мероприятия"
def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def customField = ComponentAccessor.customFieldManager.getCustomFieldObject(14020)
def linkType = issueLinkTypeManager.issueLinkTypes.find{ it.name == linkName }
def story = issue.getCustomFieldValue(customField) as Issue
doAfterCreate = {
if (story) {
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
ComponentAccessor.issueLinkManager.createIssueLink(story.id, issue.id, linkType.id, 0L, user)
}
}
I beg your pardon for the translator.
1) I want to specify tasks when creating a request on the portal.
The multiple issue pikers field helped me with this.
2) At the creation stage, I need the tasks in this field (all) to be associated with the task being created. (with the link name I need)
At the moment, the script from my example does not work. I can’t tell you what the problem is. I would be very grateful if you can help.
I am a beginner in script runner.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
1. Since you are using a multiple issue picker field, the return type of the field is a list of Issue objects, so please try:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.Issue
final def linkName = "мероприятия"
def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def customField = ComponentAccessor.customFieldManager.getCustomFieldObject(14020)
def linkType = issueLinkTypeManager.issueLinkTypes.find{ it.name == linkName }
def stories = issue.getCustomFieldValue(customField) as List<Issue>
if (stories) {
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
stories.each {
ComponentAccessor.issueLinkManager.createIssueLink(it.id, issue.id, linkType.id, 0L, user)
}
}
2. Can you confirm that you have moved your post function to be after "Creates the issue originally."?
3. If above doesn't work, please provide more details:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you very much! Everything worked out.
Tell me please. How can I delete the value in the picker field with multiple issues after filling in the links?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Tell me please. How can I delete the value in the picker field with multiple issues after filling in the links?
You can set the field to null and update the database like so:
issue.setCustomFieldValue(customField, null)
ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue, EventDispatchOption.ISSUE_UPDATED, true)
In the script we choose the Name of the connection, and if I need to specify a specific outgoing or incoming connection ?
You can specify the link as outward or inward by changing the order of arguments, like so:
ComponentAccessor.issueLinkManager.createIssueLink(it.id, issue.id, linkType.id, 0L, user)
// or
ComponentAccessor.issueLinkManager.createIssueLink(issue.id, it.id, linkType.id, 0L, user)
I hope this helps!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am sorry, you need to import the appropriate class:
import com.atlassian.jira.event.type.EventDispatchOption
issue.setCustomFieldValue(customField, null)
ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue, EventDispatchOption.ISSUE_UPDATED, true)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are most welcomed. Please accept my answer for future reference.
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.