ow to use script runner or automations to link all the tasks from the field

Evgeniy April 13, 2021

Good afternoon.
Please tell me how to use script runner or automations to link all the tasks from the field - "issue (s) piker" with the request on which this field is located.

I'm not good at scriptrunner (

1 answer

1 vote
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 23, 2021

Hi @Evgeniy,

For your requirement, you could the Post-Function in the Create transition. 

I assume that you have already added an issue picker field for your project. 

You will next need to set up the Post-Function.

Below are the print screens of the Post-Function configuration:-

1) Go to the project's workflow. Switch to the Diagram view. Next, click on the Create transition and select the Post-Function link.

image1.png

2) In the Post-Function config, click on the Add post function link.

image2.png

3) Next select the Custom script post-function [ScriptRunner] option.

image3.png

4) Once you are on the Custom script post-function page, you can add the sample code as shown in the print screen below.

image4.png

Below is the sample code for your reference:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager

def customFieldManager = ComponentAccessor.customFieldManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueLinkManager = ComponentAccessor.issueLinkManager
def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def issueManager = ComponentAccessor.issueManager

def sampleIssuePicker = customFieldManager.getCustomFieldObjectsByName("Sample Issue Picker")[0]
def sampleIssuePickerValue = sampleIssuePicker.getValue(issue) as List<String>

def availableIssueLinkTypes = issueLinkTypeManager.issueLinkTypes
def linkType = availableIssueLinkTypes.findByName("Blocks")
def sequence = 1L

sampleIssuePickerValue.each {
def destinationIssue = issueManager.getIssueByCurrentKey(it.toString())
issueLinkManager.createIssueLink(issue.id,destinationIssue.id,linkType.id,sequence,loggedInUser)
}

Please note this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

After adding the code, click on the Update button.

5) Once you have updated the post-function, you will need to bring the post-function to the very bottom as shown in the image below:-

image5.png

Once you have done that, click on the Publish button to publish your workflow changes.

Now you can try to create an issue and select the issues from the Issue Picker  Once the ticket is created, you should see the linked issues as shown in the images below:-

image6.png

image7.png

I hope this helps to solve your question. :)

 

Thank you and Kind Regards,
Ram

Suggest an answer

Log in or Sign up to answer