Hello,
Here is my scenario:
When creating an issue A, I use the "Clone an issue and links" post function on the creation transition.
This creates a clone issue, issue B, on which I make some operations through "Additional issue actions":
- Update issue B summary, issue B fixverions
- Set issue B specific custom field to a specific value
- Create links between issue B and other issues
With the script below, all the actions related to fields are working, but not the links creation.
Important thing is that the same code works in other context (basic transition for example), and that I get the summary of my issue updated with the relevant Ids of the issues I want to link issue B to:
import com.atlassian.jira.component.ComponentAccessor def issueLinkManager = ComponentAccessor.getIssueLinkManager() def authenticationContext = ComponentAccessor.getJiraAuthenticationContext() issue.summary = '[DASHBOARD] ' + sourceIssue.key + ' - ' + issue.summary issue.fixVersions = new HashSet<String>() def cfm = ComponentAccessor.getCustomFieldManager() // customfield_27012 = LPT - Niveau de test def cf_LPT_NiveauTest = cfm.getCustomFieldObject("customfield_27012") def om = ComponentAccessor.getOptionsManager() def cfConfig = cf_LPT_NiveauTest.getRelevantConfig(issue) def option_DashBoardEvol = om.getOptions(cfConfig).getOptionForValue("DashBoard - Evol", null) issue.setCustomFieldValue(cf_LPT_NiveauTest, option_DashBoardEvol ) //used for debug issue.summary = "idLPTTdb=" + sourceIssue.getKey() + " " + issue.summary issueLinkManager.getInwardLinks(sourceIssue.getId()).each { lpttdblink -> if (lpttdblink.getIssueLinkType().getName().contains('Traitement BSL')) { def idBSL = lpttdblink.getSourceObject() //used for debug issue.summary = "idBSL=" + idBSL.getKey() + " " + issue.summary issueLinkManager.createIssueLink(issue.getId(), idBSL.getId(), new Long(12000), null, authenticationContext.getLoggedInUser()) idBSL.getSubTaskObjects().each { if ((it.getIssueTypeObject().getName().contains("[BSL] Evolution")) && (it.getSummary().contains("[LPI]"))) { //used for debug issue.summary = "stBSL=" + it.getKey() + " " + issue.summary issueLinkManager.createIssueLink(issue.getId(), it.getId(), new Long(12000), null, authenticationContext.getLoggedInUser()) } } } }
Can anyone help me on this?
Many thanks,
Best regards.
So, issue linking operations need to be put in the doAfterCreate closure, as described in the docs. So
doAfterCreate = { issueLinkManager.getInwardLinks(sourceIssue.getId()).each { lpttdblink -> if (lpttdblink.getIssueLinkType().getName().contains('Traitement BSL')) { def idBSL = lpttdblink.getSourceObject() //used for debug issue.summary = "idBSL=" + idBSL.getKey() + " " + issue.summary issueLinkManager.createIssueLink(issue.getId(), idBSL.getId(), new Long(12000), null, authenticationContext.getLoggedInUser()) idBSL.getSubTaskObjects().each { if ((it.getIssueTypeObject().getName().contains("[BSL] Evolution")) && (it.getSummary().contains("[LPI]"))) { //used for debug issue.summary = "stBSL=" + it.getKey() + " " + issue.summary issueLinkManager.createIssueLink(issue.getId(), it.getId(), new Long(12000), null, authenticationContext.getLoggedInUser()) } } } } }
should do it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm a bit confused. Linking the cloned issue with its original is exactly what the Clone Issue and Link post function already does. Am I misunderstanding which issues are A & B or something??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jonny Carter When creating an issue A, with Clone Issue and Link post function, it will generate a clone issue, issue B. But A and B are not linked.
From the online doc I think what that mean is if A is set link to C, then new created clone issue B will also not link to C. But in my case, I want A link to its clone B. Anyway I can do that? If I am wrong could you show me how to link A & B?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jonny Carter How to get Issue A id and issue B's id, I did try use
sourceIssue.getKey(),sourceIssue.key
but they all return null
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@QQQ - You should be able to specify a link type and direction. From those docs:
Specify also the link type and direction… this will normally be Clones, but doesn’t have to be.
As for getting the issue keys in the additional code, sourceIssue.key should work, but it may not work unless you put it inside a doAfterCreate closure. See https://scriptrunner.adaptavist.com/latest/jira/builtin-scripts.html#_after_create_actions.
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.