Hi dear community,
I try to create an Automation (with the plugin Automation for Jira that has been bought by Atlassian) with the parameters below:
- Trigger: Value of Field "Text 1" changed
- Then For all issues where field "External ticket Id" = "Text 1"
- Action "Create a link" between the triggered issue and all issues found by the JQL / search
The trigger and the action are quite clear to design. I have more challenge about the condition. I don't know how to use a JQL seach or even a loop condition. Thank you for your help.
Romain
Hello all,
After new research and internal discussion we found a way to do it with Automation for JIRA. There is an option to compare a field with a value OR with another field.
That was exactly what I was trying to achieve.
Trigger : when field Text 4 changes on my Task issue (or any other field, but it should be the same type than External ticket id that's why I can't use my Number field)
Branch : search all Enhancement on my project
Condition : the field External ticket Id in that branch should be equal to Text 4 in the trigger issue
Action : link issues
The Automation in global
The detailed condition in the branch
Thank you again @Hana Kučerová for your help, I learned much about groovy thanks to you.
Romain
Hi @Romain VELON ,
please look at "Branch rule / related issues" component.
You should be able to select: Type of related issues: JQL ("External ticket Id" = "Text 1")
Then edit all the related issues and setup link for them.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Hana Kučerová ,
Thank you for your answer but it seems it doesn't work. The JQL is considering "Text 1" as a value in a field not as a field itself.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, I didn't understand your problem correctly, I thought it is a value.
As far as I know it is not possible to compare values of fields like this, maybe there are some applications, but I'm not sure, if they will work with Automation for Jira.
Is there any other way, how to identify the related issues?
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.
I believe that you can use the temp variable action to save one field and compare to another. Here is the explanation of the variables action:
Your rule might be something like:
Best regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bill Sheboy ,
Thank you for your answer. I believe it would have worked but "Create var" is not available on Server. Seems to be only a Cloud option for now.
I'm looking at Scriptrunner action if I can create anyhing there.
Romain
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Romain VELON ,
if you have ScriptRunner, you can create custom listener for Issue Updated event. Is it suitable for you to have groovy script in your solution? Are you familiar with groovy or should I try to prepare it for you?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Hana Kučerová ,
Yes we have Scriptrunner and I'm struggling right now with the script.
I try to do it in Automation but a Listener should work as well. In 2 words, the algorithm I try to do:
Any time field "Text 1" is updated for issue I1
Find all issues where "External Ticket Id" equals the Text 1 value from issue I1
For each issue found
Link it to I1
End For
If you're an expert and can help me on that script, I would really appreciate.
Romain
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please try something like this, maybe you will need to do some changes, but it works for me. Just create custom listener - setup your project and event "Issue Updated".
The provided script checks the changes during the issue update and continues only if "Text 1" field has been changed.
Then then JQL is created based on the new value in "Text 1" field.
Issues, where "External Ticket Id" ~ "Text 1" value, are searched (the logged in user is used for the search operation)
If there are some search results, the link between the original issue and found issues is created.
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.query.Query
final String textCustomFieldName = "Text 1"
final String ticketCustomFieldName = "External Ticket Id"
final Long issueLinkTypeId = 10003
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == textCustomFieldName}
if (!change) {
return
}
JqlQueryParser jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Long issueId = event.issue.getId()
String externalTicketId = change.newstring as String
String query = '"' + ticketCustomFieldName + '" ~ "' + externalTicketId + '"'
Query searchQuery = jqlQueryParser.parseQuery(query)
SearchResults<Issue> results = searchService.search(user, searchQuery, PagerFilter.getUnlimitedFilter())
results.getResults().each { result ->
issueLinkManager.createIssueLink(result.getId(), issueId, issueLinkTypeId, 1, user)
}.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Hana Kučerová ,
Thank you very much, I am very close to the result. I tried to do it in Automation for JIRA instead of Listener. Because my instance is shared with many projects and I prefer to manage this at the project level and not on the instance.
Anyway you'll find my code below. I don't know why but it seems the program is not able to get the custom field value "Number 1" with the syntax I'm giving.
When I replace
def number1value = issue.getCustomFieldValue(number1)
by
def number1value = "123456"
this is working correctly (I force the value instead of trying to get it from code). So something is wrong with getCustomFieldValue but I can't see what.
Thanks for your help.
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.query.Query
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
final Long issueLinkTypeId = 10003
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def number1 = customFieldManager.getCustomFieldObjectByName("Number 1")
def number1value = issue.getCustomFieldValue(number1)
def number1valueString = number1value.toString()
JqlQueryParser jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Long issueId = issue.getId()
String query = 'project = MHISAM AND "External Ticket Id" ~ "' + number1valueString + '"'
Query searchQuery = jqlQueryParser.parseQuery(query)
SearchResults<Issue> results = searchService.search(user, searchQuery, PagerFilter.getUnlimitedFilter())
results.getResults().each { result ->
issueLinkManager.createIssueLink(result.getId(), issueId, issueLinkTypeId, 1, user)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Romain VELON ,
this is really strange. I've just tested it using my instance and it works.
A few tips, what you could try:
I will try to find out any other possibilites, where the problem could be.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.