Hi,
There is multiple issue picker field on screen where I select multiple issues. I need those selected issue to be available in Issue Links.
How can I write listener for this on issue creation and issue update event?
Hi @RSP
For your requirement, since you are using the Listeners, you can do something like this:-
import com.atlassian.jira.component.ComponentAccessordef issue = event.issuedef customFieldManager = ComponentAccessor.customFieldManagerdef issueLinkManager = ComponentAccessor.issueLinkManagerdef issueManager = ComponentAccessor.issueManagerdef loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUserdef sampleIssuePicker = customFieldManager.getCustomFieldObjectsByName('Sample Issue Picker').first()def sampleIssuePickerValue = issue.getCustomFieldValue(sampleIssuePicker).toString()def issueIds = issueManager.getIssueIdsForProject(10100)def issues = issueManager.getIssueObjects(issueIds)issues.each { sourceIssue -> if(sampleIssuePickerValue.contains(sourceIssue.key)) { issueLinkManager.createIssueLink(issue.id, sourceIssue.id, 10003, 1, loggedInUser) }}
Please note, the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a print screen of the Listener configuration:-
To determine what type of Link you want to use, you will need to visit the Issue Linking page as shown below:-
Once you have decided which link type you wish to use, you will need to move your mouse over the Edit link.
You will then see the Issue Link's ID. this is the ID you will need to use in this line of code:-
issueLinkManager.createIssueLink(issue.id, sourceIssue.id, 10003, 1, loggedInUser)
Below are few test print screens:-
1) When the issue is being created, two linked issues are added as shown below:-
2) Once the issue is created, the Issue Link is automatically created as shown below:-
3) Similarly, if an issue has already been created, and the links are included as shown below:-
The issue link will also be created as shown below:-
I hope this helps to answer your question.
Thank you and Kind Regards,
Ram
Hi Ram,
Thank you so much for your response.
But the thing is I want linking should be done from both the sides like as MOCK-6 is showing PCU-8 and PCU-3 in Issue Links same should be done from PSU-6 side need to show MOCK-6 in Issue Links
Hi @RSP ,
When a link is created from one issue to another, the issues involved in the link will automatically have the link.
When the link was created in MOCK-6 to PCU-3 and PCU-8, the link was created in MOCK-6 as well as in PCU-3 and PCU-8.
There is no need to do an additional linking config.
Below are the print screens for your reference:-
I really appreciate your response. Thank you so much.
Still I have one query what if I want to apply this for all projects(Global).
Thanks and Regards,
RSP
To anyone looking at this post in 2023, we recently released HAPI early this year, and the script now can be as simple as below:
def source = event.issuedef destination = source.getCustomFieldValue('Issue Picker Field')if (destination) { source.link('blocks', destination)}
Cheers,Helmy
It looks like you're new here. Sign in or register to get started.