You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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
}
If I'm not wrong, you want to compare the field text/id which is entered during create/edit
but your current script will fetch the field value which is stored in the DB already
def CPID = customFieldManager.getCustomFieldObject("customfield_10210")
def CPIDValue = underlyingIssue?.getCustomFieldValue(CPID)
String jql = "\"Clarity Project ID\" ~ ${CPIDValue}"
so you may try this script with following lines
def CPID = getFieldByID("customfield_10210").formValue
String jql = "\"Clarity Project ID\" ~ ${CPID}"
BR,
Leo
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.