Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can we create link with current issue using script runner using listener feature

Riya Badlani April 10, 2023

I have one field 'A' that contains details of issue type 'B'.

when I create and add the value in Field A as A1 and related IssuetypeID - B1 

So I want that when issue field A is updated with A2 details old link (i.e.A1) should be update issue and change the issue link as value in custom field A  with specific link type like 'ABC'

I have written following script but it is giving error

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.link.IssueLink

import com.atlassian.jira.issue.link.IssueLinkManager

import com.atlassian.jira.user.ApplicationUser

final Issue currentIssue = getIssue(); ApplicationUser currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser() def customFieldManager = ComponentAccessor.getCustomFieldManager() def customField = customFieldManager.getCustomFieldObjectByName("Cost Details") def issueKey = issue.getCustomFieldValue(customField) as String def issueLinkManager = ComponentAccessor.getIssueLinkManager() def issueManager = ComponentAccessor.getIssueManager() def issueToLink = issueManager.getIssueObject(issueKey) /*for(final IssueLink link: ComponentAccessor.getIssueLinkManager().getIssueLinks(issue.getId())) {     if(link.getIssueLinkType().getName().equals("Cost Issue Out"))     ComponentAccessor.issueLinkManager.removeIssueLinks(issue, currentUser) } */ Collection<IssueLink> inwardLinks = issueLinkManager.getInwardLinks(currentIssue.getId()); for(final IssueLink issueLink : inwardLinks) {     if(issuelink.getIssueLinkType().getName().equals("Cost Issue Out"))     {         issueLinkManager.removeIssueLink(issueLink, context.getLoggedInUser());     } } issueLinkManager.createIssueLink(issue.id, issueToLink.id, 10840, 1, currentUser)

 

 

1 answer

0 votes
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 20, 2023

Hi @Riya Badlani

For your requirement, you could try something like this:-

import com.adaptavist.hapi.jira.issues.Issues

def issue = event.issue
def currentIssue = Issues.getByKey(issue.key)
def sampleIssuePicker = currentIssue.getCustomFieldValue('Sample Issue Picker')
def inwardLinks = currentIssue.inwardLinks
def linkedIssues = inwardLinks.sourceObject

if (linkedIssues.size() > 0) {
inwardLinks.each {issueLink ->
linkedIssues.each { linkedIssue ->
issue.unlink(issueLink.issueLinkType.inward.toLowerCase(), linkedIssue)
}
}
}

if (sampleIssuePicker) {
currentIssue.update {
def links = sampleIssuePicker.collect { Issues.getByKey(it as String) }
setLinks('is blocked by', *links)
}
}

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

Below is a screenshot of the Listener configuration:-

listener_config.png

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram 

Riya Badlani April 23, 2023

Hi Ram,

Thanks. I will check and let you know if further help is needed.

 

Best Regards,

Riya Badlani

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 26, 2023

Hi @Riya Badlani

Has your question been answered?

If yes, please accept the solution.

Thank you and Kind regards,

Ram

Riya Badlani April 27, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_,

Thanks for asking.

No it is not working for me.

But Resolved it by JWME, Event based action functionality by using different code for create link and execute unlink Issue post function which condition execution.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events