Forums

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

Behaviours: Checking that Text Field Value Doesn't Already Exist in Current Issue's Jira Project

Lacey Also
Contributor
October 21, 2020

Trying to make sure a custom text field value (single line) does NOT already exist in the current issue's project. Right now this script is doing nothing and throws no errors on the Behaviors screen.

 

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
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.opensymphony.workflow.InvalidInputException

def issue = underlyingIssue
def CPID = customFieldManager.getCustomFieldObject("customfield_10210")
def CPIDValue = underlyingIssue?.getCustomFieldValue(CPID)
String jql = "\"Clarity Project ID\" ~ ${CPIDValue}"
List<MutableIssue> jqlIssues = getIssuesFromJQL(jql)

if (jqlIssues) {
throw new InvalidInputException("Clarity Project ID already exists in issues: ${jqlIssues}")
}
return true

List<MutableIssue> getIssuesFromJQL(String jqlQuery) {
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueManager issueManager = ComponentAccessor.getIssueManager()
JqlQueryParser jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
Query query = jqlQueryParser.parseQuery(jqlQuery)
SearchResults searchResults = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
List<MutableIssue> mutableIssueList = searchResults.getResults().collect { issue -> issueManager.getIssueObject(issue.getId()) }
return mutableIssueList
}

 

1 answer

Suggest an answer

Log in or Sign up to answer
2 votes
Raziman Dom - Ricksoft
Community Champion
December 23, 2020

Hi Vidhya,

Please try using these:

JDBC URL: jdbc:relique:csv:/tmp

Driver class name: org.relique.jdbc.csv.CsvDriver

Download driver from here. It should be the same driver anyway: https://sourceforge.net/projects/csvjdbc

Screenshot 2020-12-24 at 12.07.10 PM.png

Raziman Dom - Ricksoft
Community Champion
December 23, 2020

Screenshot 2020-12-24 at 12.23.49 PM.png

Vidhya Mohan
Contributor
December 28, 2020

thanks @Raziman Dom - Ricksoft . The instruction of script runner worked. I did not create the jar file properly. :)

Raziman Dom - Ricksoft
Community Champion
December 28, 2020

Cool! Please accept my answer @Vidhya Mohan if you are able to resolve your issue ;) 

TAGS
AUG Leaders

Atlassian Community Events