Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Chain of reaction: How to access the linked issues, when they are set in the same transaction

Thilo Brause
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 22, 2022

Using Scriptrunner, I defined a postfunction for a transition. In that transition a new issue is created and one of the linked issues of the source issue is set in the issue picker of the new issue.

Works fine.

 

But:

The above mentioned source issue itself is created by a transition of a third issue. And all issue links are set programmatically on creation.

Which still works fine.

 

However, in certain circumstances the mentioned source Issue should travel through the above mentioned transition directly after creation (using a FastTrack-Transition-Postfunction in the Create-Transition). In that situation, accessing the linked issues of the source issue fails and returns an empty list of issues.

So it looks to me like the setting of the linked issues during the creation of the source issue and accessing the linked issues happens in the same internal transaction, therefore the linked issues are not yet available.

So how can I tell Jira to first completely create the source issues (including its links to other issues), before starting on the transition of that source issue?

Or is there any other possibility for the root cause of this behaviour, that I overlooked?

 

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.
May 3, 2022

Hi @Thilo Brause

You could try including the Listener for this requirement, i.e., a Custom Listener with the IssueCreated event.

So, once the Post-Function triggers the Fast-Track and the Issue is created, the Listener can be used to update the Issue and set the value for the Issue Picker.

It would be good to share your code to get a better understanding.

Thank you and Kind regards,

Ram 

Thilo Brause
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 4, 2022

Dear @Ram Kumar Aravindakshan _Adaptavist_ ,

yes, defining a Listener would be a possible workaround. But I would prefer to understand and correct ther current behaviour.

This is my implementation (the relevant parts, the complete code would fill several pages and contain dozens of calls to helper-methods):

a) Creating the second issue and setting its values in a postfunction of the first issue

MutableIssue newIssue = ComponentAccessor.getIssueFactory().getIssue()
...
//Setting all necessary fields
...
newIssue = ComponentAccessor.getIssueManager().createIssueObject(user, newIssueParams) as MutableIssue
ComponentAccessor.getIssueLinkManager().createIssueLink(newIssue.getId(), toBeLinkedIssue.getId(), Globals.IssueLinkTypes.RELATES, 1, user)

 b) The third issue is created in a postfunction on the "Start progress"-Transition of the second issue

//RetrievedLinkedIssues is null in case that the code from a) and b) is connected using c)
//If a) and b) are triggered separately, everything works fine
def retrievedLinkedIssue = ComponentAccessor.getIssueLinkManager().getOutwardLinks(secondIssue.get())
.stream().filter({it.getLinkTypeId() == Globals.IssueLinkTypes.RELATES})
.map({it.getDestinationObject()}).findFirst()

MutableIssue newIssue
= issueFactory.getIssue()
...
//Setting all necessary fields
...
issueManager.createIssueObject(toCreateUser, newIssue)
issueLinkManager.createIssueLink(newIssue.getId(), retreievedLinkedIssue.getId(), Globals.IssueLinkTypes.RELATES, 0, toCreateUser)

c) FastTrack-Condition in the create-Transition of the second issue, connecting the code of a) and b) in one transaction

image.png

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.
May 5, 2022 edited

Hi @Thilo Brause

I need to check with you; in your last code, you have shown:-

MutableIssue newIssue = ComponentAccessor.getIssueFactory().getIssue()

Why exactly are you using the ComponentAccessor to invoke the issue when you can directly invoke the issue variable in the Post-Function?

For example:-

def issue = issue as MutableIsuse

In your description, you have mentioned:-

However, in certain circumstances the mentioned source Issue should travel through the above mentioned transition directly after creation (using a FastTrack-Transition-Postfunction in the Create-Transition)

Triggering the approach is not 100% guaranteed to be successful when using the Post-Function for the Create transition, which is why I suggested including the Listener to ensure that it will trigger only after the issue has been created.

Thank you and Kind regards,

Ram

Thilo Brause
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 5, 2022

Dear @Ram Kumar Aravindakshan _Adaptavist_ ,

I use ComponentAccessor with the IssueFactory to create a new Issue, which I am doing twice in the mentioned process. Each time, I am using some values of the active issue (binded to the variable issue) to fill the values of the new Issue.

So in the part 

//Setting all necessary fields

there are statements like

newIssue.setSummary(issue.getSummary)
newIssue.setPriority(issue.getPriority)

 

I do not understand your statement with the 100% - why shouldn't the postfunction in the create transition work?

 

Best Regards,

   Thilo 

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events