Hi Team,
I have a Field in project Called "Host IP" and "Mac Address" these are text Field type custom Fields.
Here If the Value in those Fields matches with other issues those issues has to link to the present created issues automatically.
example:
1) I created a issue and i gave the value in those two fields and I created
"Host IP : 10.1.4.88"
"Mac Address : SB1024860"
if these value matches to previously issues or closed issue or in progress issues it has to Link automatically in the Present issue.
2) Now when We look into this post on the right hand side we have seen a "Related Content" right it's showing some retlated content same like that.
I have seen an add-on its its finds the similar issues depend up on value
https://marketplace.atlassian.com/apps/1212538/similar-issues-finder?hosting=server&tab=overview
can you please suggest me is there any way to do with groovy script by creating a script filed
Thanks,
Kumar.
Hi Kumar,
The best way to do this is write script listener with Script Runner or My Groovy addon. You just need get value of this fields and put them in jql query. Next you can link issue with issues you find with help this query. Here are some helpfull links
https://scriptrunner.adaptavist.com/latest/jira/recipes/misc/running-a-jql-query.html
https://docs.atlassian.com/software/jira/docs/api/7.12.0/index.html?overview-summary.html
Hi @Tomasz Bryła Thanks For your response
Here I created a
Script Field > Issue Picker
In that I gave a name for the Field and added Query like :
" project = "XYZ" AND assignee = currentUser() "
and I added that Script Field to my screens The Result is it will Show the Issues that i have assigneed only
If I open another issue which i'm not assigned for the issue still it will show my issues which i have assigned in that Script field
It is working like whoever login to jira only that particular user assigned issues will display in that field.
But here i need the Jql Filter query that have mapp the Custom Filed values
any suggestions please
Thanks,
Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Kumar
Sorry for delay. Here is a code which linked issues with same fields value.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link
def issueManager = ComponentAccessor.getIssueManager()
//def currentIssue = issueManager.getIssueObject("TEST-11")
def currentIssue = event.getIssue()
def linkManager = ComponentAccessor.getIssueLinkManager()
def cfm = ComponentAccessor.getCustomFieldManager()
def jqlParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def ipVal = currentIssue.getCustomFieldValue(cfm.getCustomFieldObjectByName("IP"))
def macVal = currentIssue.getCustomFieldValue(cfm.getCustomFieldObjectByName("MAC"))
def jql = jqlParser.parseQuery("ip = ${ipval} and mac = ${macVal}")
def results = searchProvider.search(jql, user, PagerFilter.getunlimitedFilter())
results.getIssues().each {documentIssue ->
queryIssue = issueManager.getIssueObject(documentIssue.id)
if(queryIssue != null) {
linkManager.createIssueLink(currentIssue, queryIssue, 10003, 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 @Tomasz Bryła Thanks for your response
Can you please tell me Where and how exactly i can use this script
Thanks,
Kumar
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 @Tomasz Bryła I have tested this script in Script Console Here are the Logs it provided
Here I did not understand the How the script will work if i use the "Script Listener"???
Logs:
2019-01-17 21:34:10,129 WARN [common.UserScriptEndpoint]: Script console script failed: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1347.groovy: 6: unable to resolve class com.atlassian.jira.issue.link @ line 6, column 1. import com.atlassian.jira.issue.link ^ 1 error
Here I have modified the script
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link
def issueManager = ComponentAccessor.getIssueManager()
//def currentIssue = issueManager.getIssueObject("SI-2644")
def currentIssue = event.getIssue()
def linkManager = ComponentAccessor.getIssueLinkManager()
def cfm = ComponentAccessor.getCustomFieldManager()
def jqlParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def uidVal = currentIssue.getCustomFieldValue(cfm.getCustomFieldObjectByName("UID"))
def hostVal = currentIssue.getCustomFieldValue(cfm.getCustomFieldObjectByName("Host"))
def jql = jqlParser.parseQuery("UID = ${uidval} and Host = ${hostVal}")
def results = searchProvider.search(jql, user, PagerFilter.getunlimitedFilter())
results.getIssues().each {documentIssue ->
queryIssue = issueManager.getIssueObject(documentIssue.id)
if(queryIssue != null) {
linkManager.createIssueLink(currentIssue, queryIssue, 10003, 1, user )
}
}
Can you please take a look and can you please suggest me how exactly i have to perform this script
Thanks,
Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In console you must comment
def currentIssue = event.getIssue()
And uncomment
//def currentIssue = issueManager.getIssueObject("SI-2644")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Tomasz Bryła Thanks for your response
Here is the screen short that I Have tried in Script Console
Can you please explain me how exactly if add this script to script Listener
Where can i find the similar issues if it is matched the values
Thanks,
Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry @Kumar I gave you a wrong code with some issues, this is fine.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.user. ApplicationUser
def issueManager = ComponentAccessor.getIssueManager()
def currentIssue = issueManager.getIssueObject("TEST-11")
//def currentIssue = event.getIssue()
def linkManager = ComponentAccessor.getIssueLinkManager()
def cfm = ComponentAccessor.getCustomFieldManager()
def jqlParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() as ApplicationUser
def queryIssue
def ipVal = currentIssue.getCustomFieldValue(cfm.getCustomFieldObjectByName("IP"))
def macVal = currentIssue.getCustomFieldValue(cfm.getCustomFieldObjectByName("MAC"))
def jql = jqlParser.parseQuery("ip = ${ipVal} and mac = ${macVal}")
def results = searchProvider.search(jql, user, PagerFilter.getUnlimitedFilter())
results.getIssues().each {documentIssue ->
queryIssue = issueManager.getIssueObject(documentIssue.id)
if(queryIssue != null) {
linkManager.createIssueLink(currentIssue.Id, queryIssue.Id, 10003, 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 @Tomasz Bryła Thanks for your Script the script does not have any errors
Here I'm wondering were i can see the Similar issues on issue view screen
can you please explain more about please
Thanks,
Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This script will link issues with same field value to your new issue. Add this script as listener and use Issue Created Event
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Tomasz Bryła thanks for your response
Here are the logs that have generated i created a issue with the field value
Logs:
2019-01-17 22:45:53,065 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2019-01-17 22:45:53,065 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script> com.atlassian.jira.jql.parser.JqlParseException: com.atlassian.jira.jql.parser.antlr.RuntimeRecognitionException at com.atlassian.jira.jql.parser.DefaultJqlQueryParser.parseClause(DefaultJqlQueryParser.java:96) at com.atlassian.jira.jql.parser.DefaultJqlQueryParser.parseQuery(DefaultJqlQueryParser.java:32) at Script1382.run(Script1382.groovy:20) Caused by: com.atlassian.jira.jql.parser.antlr.RuntimeRecognitionException at com.atlassian.jira.jql.parser.antlr.JqlLexer.checkAndSet(JqlLexer.java:100) at com.atlassian.jira.jql.parser.antlr.JqlLexer.mSTRING(JqlLexer.java:1676) at com.atlassian.jira.jql.parser.antlr.JqlLexer.mTokens(JqlLexer.java:2656) at org.antlr.runtime.Lexer.nextToken(Lexer.java:85) at org.antlr.runtime.BufferedTokenStream.fetch(BufferedTokenStream.java:143) at org.antlr.runtime.BufferedTokenStream.sync(BufferedTokenStream.java:137) at org.antlr.runtime.CommonTokenStream.setup(CommonTokenStream.java:137) at org.antlr.runtime.CommonTokenStream.LT(CommonTokenStream.java:94) at com.atlassian.jira.jql.parser.antlr.JqlParser.query(JqlParser.java:217) at com.atlassian.jira.jql.parser.DefaultJqlQueryParser.parseClause(DefaultJqlQueryParser.java:89) ... 2 more
those values i gave to some previous issues but after creating an issue on View screen i have not seen any similar issues
Thanks,
Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Tomasz Bryła I have resolved this task so I need an small help in my script
the result of my script
When the Value is given in the "Text Field" so it will mapp that value with old issues and it will give a result in a another "Text Field" like ( 2 Times [issue keys] ) like this it will display the result
here in my script if I add to display issue keys for those issue keys i have an "Hyperlink"
if i call the instead of issue key if call the related issue Summary its showing the result just like text so i need to add the Hyper link to Summary as well
can you please suggest me how to do this
Thanks,
Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tomasz Bryła when we try this script, the current issue links to itself. Do you know why this is, and how to avoid it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Juliane Jacobsen is the above script is worked for you if it is can you please tel me what are the changes you have made and how its works for you
thats helps me
Thanks,
Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Juliane Jacobsen and @Kumar Thanks for the info so far. I'm trying to run this and get the folowing error, can you please advise me on this?
My getCustomFieldValue looks like this:
def ipVal = currentIssue.getCustomFieldValue(cfm.getCustomFieldObjectByName("Serial Number"))
Thank you!
2019-11-15 12:49:36,620 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2019-11-15 12:49:36,622 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script> java.lang.NullPointerException: Cannot invoke method getCustomFieldValue() on null object at Script2.run(Script2.groovy:17)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!
Join an Atlassian Community Event!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.