When I am using '$' sign in groovy script for behaviour in jira, I am getting compliation error.
Objective: Trying to validate summary field. Not allowing duplicate summaries. Searching the exact text in summary and making it case-insensitive search.
JQL query which is working fine in Issue Navigator:
issueFunction in issueFieldMatch("project = "ABC and key !=AB-1", "Summary", "^(?i)Test$")
Script I tried:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.searchSearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.Issue
def summaryObj = getFieldById(getFieldChanged())
def summary = summaryObj.getValue()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issue = underlyingIssue
if(issue == null)
{
return
}
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def query = jqlQueryParser.parseQuery("issueFunction in issueFieldMatch('project = Cluster and key!= "+issue.key+"', 'Summary', '^(?i)"+summary+"$')")
if(results.getTotal()>0)
{
summaryObj.setError("Issue Summary already exists.")
}
else
{
summaryObj.clearError()
}
I am getting error in the line I have made bold as Illegal String Body character after $ sign. I think it is because groovy performs String Interpolation also using $ sign. How to get the JQL accepted in this script?
Kindly help.
Thanks and Regards,
Swapnil Srivastav
Use \ before any character that can be interpreted improperly. So it would be:
def query = jqlQueryParser.parseQuery("issueFunction in issueFieldMatch('project = Cluster and key!= \"+issue.key+\"', 'Summary', '^(?i)\"+summary+\"\$')")
I do not know if you need to do it before ' characters, you need to check that.
I made similar one:
def query = jqlQueryParser.parseQuery("issueFunction in commented(\"by ${person} after startOfDay(-1d) before endOfDay(-1d)\") AND project = \"PCS\"");
Hello @Damian Wodzinski ,
Thanks for your response.
I tried using \ and \\ before $. Both do not give a compilation error but do not get the task done.
I guess that is because the regular expression meaning is altered in that case.
Regards,
Swapnil Srivastav.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Why dont you put Regex as variable, and then add reference to your JQL part in script?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Damian Wodzinski ,
Could you please let me know how to do that.
I have not worked with regular expressions before.
Thanks and Regards,
Swapnil Srivastav.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you paste the whole JQL commend directly from Jira? Is it working there?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Damian Wodzinski ,
Yes it is working there. I cannot paste data from JIRA. Here is the exact JQL
issueFunction in issueFieldMatch("project = "ABC and key !=AB-1", "Summary", "^(?i)Test$")
Thanks and Regards,
Swapnil Srivastav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use that:
def query = jqlQueryParser.parseQuery("issueFunction in issueFieldMatch(\"project = 'ABC' AND key != AB-1\",\"Summary\",\"^(?i)Test\$\")")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Damian Wodzinski ,
JQL:
issueFunction in issueFieldMatch("project = ABC and issuetype = "DE", "Summary", "^(?i)Test$")
and for groovy:
issueFunction in issueFieldMatch("project = ABC" and key != ${issue.key}", "Summary", "^(?i)${summary}\$")
works fine for me.
Thanks a lot for your response
Best Regards,
Swapnil Srivastav.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @SWAPNIL SRIVASTAV ,
Thank you so much for the example you provided showing how to use the subquery by including multiple parameters.
Using your example and fitting it to my use case made all the difference between the query timing out and running amazingly fast.
My use case was
issueFunction in issueFieldMatch("project = ACT AND labels = S4WW AND summary ~ lifecycle.intake.firstkick", "description", "intake_date => 2021-04")
Best Regards,
Joe
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.
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.