Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Creating issue links using Clone issue and links post function, in creation transition (JIRA 6.1.2) Edited

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.

1 answer

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.

@Jonny Carter  Is there anyway I can link issue A with issue B here?

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??

@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?

@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 

@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. 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June ask me anything (AMA)

Hello Community members! We’re wrapping up the end of JSM June with an Ask Me Anything (AMA) with the Jira Service Management product team. This is your chance to ask all your ITSM questions to o...

146 views 9 10
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you