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)
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:-
I hope this helps to answer your question. :-)
Thank you and Kind regards,
Ram
Hi Ram,
Thanks. I will check and let you know if further help is needed.
Best Regards,
Riya Badlani
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Has your question been answered?
If yes, please accept the solution.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.