Hi all,
We have transition called duplicate when use clicks it window opens with field Linked Issue then user choose as duplicate value then we will have another field call Issue (issue searchable field ) for this field how we write validator or scriptrunner script to validate that enter key is bug type then only transition otherwise through error massage (refer attached screenshot for more)
Hello @Dayanand ,
Perhaps you can refer to the documentation below for more information:-
With some tweaking, you should be able to configure a Simple scripted validator [ScriptRunner] in your workflow with the below script:-
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.IssueFieldConstantsimport com.atlassian.jira.issue.fields.IssueLinksSystemFieldimport com.opensymphony.workflow.InvalidInputExceptionimport webwork.action.ActionContextdef fieldManager = ComponentAccessor.getFieldManager()def issueManager = ComponentAccessor.getIssueManager()def linksSystemField = fieldManager.getField("issuelinks") as IssueLinksSystemFielddef request = ActionContext.getRequest()if (request) { def params = request.getParameterMap() def issueLinkingValue = linksSystemField.getRelevantParams(params) as IssueLinksSystemField.IssueLinkingValue for(def issueKey: issueLinkingValue.linkedIssues) { def currentIssue = issueManager.getIssueByKeyIgnoreCase(issueKey) if(!currentIssue.getIssueType().getName().equals("Bug")) { return false } } return true}
You might need to tweak the script further for your requirements.
Hope this helps.
Regards.
Hi @Dayanand
Your requirement can be achieved very easily using the ScriptRunner Server-Side Behaviour.
There is no need to use the Workflow Validator for this.
Below is a sample working code for your reference:-
import com.adaptavist.hapi.jira.issues.Issuesimport com.onresolve.jira.groovy.user.FieldBehavioursimport groovy.transform.BaseScript@BaseScript FieldBehaviours behavioursdef linkedIssues = getFieldById('issuelinks-issues')def linkedIssuesValue = linkedIssues.value as List<String>linkedIssues.clearError()linkedIssuesValue.each { def issue = Issues.getByKey(it) if (issue.issueType.name != 'Story') { linkedIssues.error = 'Only Story Types Are Allowed' }}
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications. In the sample code above, I have provided a scenario where only the Story issue type should be permitted in the Linked Issue field. However in your case, since you want to check this against the Bug issue type, you will need to make the required modification in the if condition.
Below is a screenshot of the Behaviour configuration:-
I have added a Server-Side Behaviour for the Linked Issue field in the configuration above.
In the code, I have added a very basic validation on the Linked Issue field that will only allow Story-type issues. If any other issue type is selected, it will return the error message, and the issue will fail to be created.
Below are a couple of test screenshots for your reference:-
1. For the test case below, I am going to select 2 issues: one is of the Story type, and the second is of the Bug-type, as shown in the screenshot below:-
2. When the Story type issue is added, as expected, no error message is returned, as shown in the screenshot below:-
3. However, if the Bug issue type is added, as expected, the error message is displayed as shown in the screenshot below:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
@Adrien Low _ServiceRocket_ ,
Thank you for the such valuable support. kindly help me to sort error after pasting above code into Simple scripted validator as below
on line
Also, refer attached screen shot for complete error
@Adrien Low _ServiceRocket_
script runner plugin Installed version: 7.8.0 and code supported versions looks fine and usig JIRA server 8.20.12
@Ram Kumar Aravindakshan _Adaptavist_ ,
Thank you for the complete solution however facing below package error
any help appreciated
script runner plugin Installed version: 7.8.0 and code supported versions looks fine and using JIRA server 8.20.12 let me know do i need to update plugin or any way i can create Issue object to solve this error?
Right, your getting the error message from the import statement because the current ScriptRunner version you are using doesn't support the HAPI feature. Hence, it's not able to invoke the classes from HAPI's API.
Please upgrade your ScriptRunner plugin to the latest release. It will resolve the problem.
It looks like you're new here. Sign in or register to get started.