Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

how do I link a field of pickers with multiple issues to tasks?

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)
}

1 answer

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.

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."?

post function orders.png

 

3. If above doesn't work, please provide more details:

  • Are you using "Custom script post-function"? or other ScriptRunner's built-in post-functions (end with "[ScriptRunner]"):
    list of post functions.png

  • Can you provide screenshots of your configurations?
Like Evgeniy likes this

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?

One more thing, in the script we choose the Name of the connection, and if I need to specify a specific outgoing or incoming connection ?

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!

Like Evgeniy likes this

Added the code to the end. Returns an error when resetting values.

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)

Thank you very much! Everything is working.
Special thanks for your patience and explanation.

I really appreciate it.

You are most welcomed. Please accept my answer for future reference.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you