Hey
Looking for some general advice and pointing in the right direction!
Tools: Jira, Scriptrunner , JSU
Field: Artefact ID (single line text type)
Problem: We want to prevent users entering duplicate values on this field on a transition screen. Ideally we would show a error message telling the user it is a duplicate value. And if possible link this ticket to the duplicate when they enter a unique Artefact ID.
So I believe we would need to do some validation using SQL on the database for this custom field values. Is that possible using groovy/scriptrunner?
Hoping to avoid installing/purchasing any other plugins and do this with scriptrunner
Any help much appreciated
Rich
HI @Richard Duffy ,
Do you resolved is request?
I have the same request .
I try to use this script but i dont have success result.
if you have some idea please tell me
thanks
HI Andrey
No we decided to simplify our business process, best of luck!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for you response ,
Thanks for you response ,
I have resolved the request
regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Andrey
Did you manage to script this? If so can you share with us?
Thanks
Richard
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes i share my script :
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.component.ComponentAccessor
def parser = ComponentAccessor.getComponent(JqlQueryParser)
def query = parser.parseQuery("project = ${issue.projectObject.key} and 'Wallet Address' = ${cfValues['Wallet Address'].value}")
def searcher = ComponentAccessor.getComponent(SearchService)
def kount = searcher.searchCountOverrideSecurity(currentUser, query)
return kount == 0
My custom field is Wallet Address
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Richard,
What you need is a scripted validator that would run a JQL search and if that returns any results then show an error to the user. The logic is as follows:
1. User enters some artefact id on a transition screen
2. A JQL search is ran with the following query: "Artefact ID = ${artefact id from screen}"
3. Assuming all artefact ids are unique if that search returns any results then the user is trying to submit already existing id
4. Show an error message with the ticket with the same id
The code for such validator is as follows:
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
Issue issue = issue
CustomField artefactId = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Artefact ID")
String artefactIdValue = issue.getCustomFieldValue(artefactId)
String jql = "\"Artefact ID\" ~ ${artefactIdValue}"
List<MutableIssue> jqlIssues = getIssuesFromJQL(jql)
if (jqlIssues) {
throw new InvalidInputException("Artefact 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.getIssues().collect { issue -> issueManager.getIssueObject(issue.getId()) }
return mutableIssueList
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ivan
Thanks for the reply. This looks very promising.
Let me start with a quick question?
Q. Should I use a "custom script validator" or "simple script validator" and what is the difference between the two options?
I have tried the custom script validator, it does give some errors/warnings
Outcome:
No effect on the workflow transition screen when entering a duplicate
*** Note ***
my field (Artefact ID) - Select list is "Free Text Searcher"
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.