Hello Everyone,
I am trying to develop a scriptrunner script that will delete issue-links on the issue that calls the IssueLinkCreatedEvent. This deletion has to check some requirement in the main issue but i am not able to always get the correct main issue.
This is because of 2 reasons:
1. The IssueLinkCreatedEvent does not have any information about the issue that has fired the IssueLinkCreatedEvent, so the following line will give back a null because the event does not contain a issue object:
Issue issue = event.issue
2. The event also doesn't contain the direction of an issue-link creation:
I know i can get the source and destination object by the following code
IssueLink issueLink = event.issueLink
Issue issueDestination = issueLink.destinationObject()
Issue issueSource = issueLink.getSourceObject()
But the problem is when you select outward or inward type of the link the destination and source will swap issue id's. Because of this i cannot get the main parent issue out because the IssueLinkCreatedEvent also doesn't provide information on which direction the link is going!
For example if i have a issuelink with:
Name: Test
Outward: Tests
Inward: Is tested by
The IssueLinkCreatedEvent does not contain the direction of a outward or inward issue-link.
Two possible solutions that will solve my issue:
1. Does someone have any idea how to get the issue that fires the IssueLinkCreatedEvent!
or
2. Is there a way to get or provide the IssueLinkCreatedEvent with the correct direction it is going ? for example how to know if it is "is tested by" or "Tests"
Hi Bart
I had the exact same question / challenge. (wanting to create a link listener to calculate the Safety Level Field of a Test based on the linked Requirements.)
I understood the issue like this: the IssueLink Events are only listening if a Link is created or deleted. The Link can be created from both sides e.g. Test issue or Requirement issue so it doesn't matter for the event which issue is triggering it.
I have worked around in my listener by checking the issue type consistency.
For the Tests Link the source issue would always be a Test issue type -> tests-> destination issue shall be sthg else like Requirement.
So I have something like this in my Listener code:
// check for IssueLinkType Name= Test - if no Test, exit
if (!event.issueLink.issueLinkType.name.equals("Tests")) {
mylog.debug "Link not of Type Tests but ${event.issueLink.issueLinkType.name}->exit"
return
}
Issue issue = event.getIssueLink().getSourceObject()
// check for SourceIssue Type = Test - if no, exit (wrong link direction chosen)
if (!issue.issueType.name.toLowerCase().equals("test")) {
mylog.warn "Source issue ${issue.key} not of Type Test but ${issue.issueType.name} ->exit"
return
}
Issue destinationIssue = event.getIssueLink().getDestinationObject()
// check for Destination Issue Type = Requirement - if no, exit
if (!destinationIssue.issueType.name.toLowerCase().contains("requirement")) {
mylog.warn "Destination issue ${destinationIssue.key} not of Type Requirement but ${destinationIssue.issueType.name} ->exit"
return
}
Hello @Bart_Joosten
I believe your problem was solved in this thread :)
https://community.atlassian.com/t5/Jira-questions/How-to-get-current-issue-when-I-use-IssueLinkCreatedEvent-event/qaq-p/879597
See the accepted solution 🚀
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The answer on that thread did not give me the correct solution:
I am looking for the main parent object that is firing the event and not the source or destination object Issues.
Because when you change the link type from inward to outward they will swap there place of the id's.
So from the SourceID or DestionationID i cannot get which one is the main issue that is execution the event, for example:
I have a issue called Issue-1 and want to link this issue to Issue-2:
When i select the link type Tests(Inward), the source and destination id will be:
SourceID: 700 (Issue-1)
DestionationID: 800 (Issue-2)
but when i select the link type Is tested by(Outward) it will be:
SourceID: 800 (Issue-2)
DestionationID: 700 (Issue-1)
So how can i get the issue that is firing the event when it is in the first link type the SourceID but in the counter action it is the DestionationID?
And the event is not giving me back if it is doing the outward or inward action of the issuelink?
So it would be help full if the IssueLinkCreatedEvent would have the id or key of the issue that is firing the event. Or if it would have the name of the inward or outward link it is executing!
Hope it's more clear now!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Bart_Joosten
From what I see in the ScriptRunner docs the information about the issue from which the event is being fired is not available. I understand this makes sense given you are listening to the creation of a Link between issues, which can be done both explicitly through UI from one issue to another or through scripts or API calls, scenarios in which there is no defined 'origin issue' (so to speak).
What are you trying to accomplish exactly?
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.
Hi @Fernando Bordallo
Actions:
Question:
The current values that the event is given and where you can transform them into:
ID: Current issue-link id that is counting up
SourceID: Issue object: Source issue
DestionationID: Issue object: Destination issue
IssuelinkType: The name of the issuelink: Test
I want to know the issue object that the user is calling the IssuelinkCreatedEvent on or the issuelinktype that he is using, at this moment the event does not supply this information. because i only want to allow specific types of links on issue 1 i need to know the type of the link he is creating or on which ticket he is creating the issuelink on.
Because the DestionationID and SourceID are different on the type of link you have selected i can never tell my scriptrunner script what is the main issue he needs to check the links on.
So i think the event is missing a parameter of the current issuekey or the issuelinkType parameter is to global and is giving only back the name and should be giving back the type inward or outward! for example 2 events that should solve the problem whit if they would provide one of the following parameters:
Current event is giving back:
eventissuelink:com.atlassian.jira.issue.link.IssueLinkImpl@456f4236[id=170506,sourceId=212096,destinationId=211890,issueLinkType=10700]
Should be one of the following:
eventissuelink:com.atlassian.jira.issue.link.IssueLinkImpl@456f4236[id=170506,sourceId=212096,destinationId=211890,issueLinkType=10700,issuelinkDescription=[Tests] Or [IsTestedby]]
eventissuelink:com.atlassian.jira.issue.link.IssueLinkImpl@456f4236[id=170506,sourceId=212096,destinationId=211890,issueLinkType=10700,ExecutionIssue=[Issue1]]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Fernando Bordallo
Actions:
Question:
The current values that the event is given and where you can transform them into:
ID: Current issue-link id that is counting up
SourceID: Issue object: Source issue
DestionationID: Issue object: Destination issue
IssuelinkType: The name of the issuelink: Test
I want to know the issue object that the user is calling the IssuelinkCreatedEvent on or the issuelinktype that he is using, at this moment the event does not supply this information. because i only want to allow specific types of links on issue 1 i need to know the type of the link he is creating or on which ticket he is creating the issuelink on.
Because the DestionationID and SourceID are different on the type of link you have selected i can never tell my scriptrunner script what is the main issue he needs to check the links on.
So i think the event is missing a parameter of the current issuekey or the issuelinkType parameter is to global and is giving only back the name and should be giving back the type inward or outward! for example 2 events that should solve the problem whit if they would provide one of the following parameters:
Current event:
eventissuelink:com.atlassian.jira.issue.link.IssueLinkImpl@456f4236[id=170506,sourceId=212096,destinationId=211890,issueLinkType=10700]
Solving event 1:
eventissuelink:com.atlassian.jira.issue.link.IssueLinkImpl@456f4236[id=170506,sourceId=212096,destinationId=211890,issueLinkType=10700,issuelinkDescription=[Tests] Or [IsTestedby]]
Solving event 2:
eventissuelink:com.atlassian.jira.issue.link.IssueLinkImpl@456f4236[id=170506,sourceId=212096,destinationId=211890,issueLinkType=10700,ExecutionIssue=[Issue1]]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello again @Bart_Joosten
I see what you are trying to do. As I stated before I don't think listening to the issueLinkCreated is the correct approach to obtain this information as this event cannot contain the information on the issue the link is created from with a 100% correctness.
I believe your best solution would be to listen to issueUpdated events and look into the changelog to see if the update relates to a new issueLink having been created.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Fernando Bordallo
The issue update event does not get triggered when you are creating a link because the event IssueLinkCreatedEvent will not call a issue update event somehow. So this action is not possible any other solutions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bart_Joosten, thanks for bringing this to the attention of Adaptavist Support. I believe @Fernando Bordallo is right to identify this question as relating more to the Jira APIs than to ScriptRunner specifically: there is no way for SR to retrieve the information you seek because Jira simply does not record it. IssueLinkCreatedEvent is not an exclusively issue-related event (i.e. it does not arise solely from the creation/updating/transition/etc. of a single issue) and thus identifying it with one issue is not always semantically appropriate. I do agree that in situations where such an identification does make sense, it would be useful information to have, but this is something to address to Atlassian.
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.