Question Scriptrunner "field(s) required validator "

Frank Lohfeld May 8, 2024

Here is the translation to English:

"I have implemented a Script Runner 'field(s) required validator' in my Jira workflow. This forces users to fill in the 'Fix Version/s' and 'Affected Version/s' fields as soon as the ticket moves to the 'Done' status. This part works well.

However, I want the assignee to be forced to fill out these fields only if the resolution is also set to 'Done'. Otherwise (for example, with the resolutions 'Won't Do' or 'Duplicate'), the validator should not be executed. There is a 'Condition' field in the validator for this purpose.

I entered the following script there,

import com.atlassian.jira.component.ComponentAccessor

def resolution = ComponentAccessor.getIssueManager().getIssueObject(issue.key).getResolutionObject()
def isResolutionDone = resolution?.name == "Done"

// Return true, wenn die Resolution "Done" ist, sonst false
return isResolutionDone

 but unfortunately, it does not work. It does not prompt for the two fields even when the resolution is 'Done', and just closes."

Have you a solution or hint for me?

Thank you for your help

2 answers

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 8, 2024

While what Tuncay suggested in the other answer will work, in the context of a condition script on a scriptrunner field required validator, you can just access the resolution directly from the built-in "issue" variable.

Your condition should work as a single line:

issue.resolution?.name == 'Done'

When the condition is true, the validator will evaluate the list of fields you flagged as required.

When the condition is false, the validator will be skipped.

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 8, 2024

Hi @Frank Lohfeld 

If you retrieve an issue using IssueManager, it won't display the updated values that are going to be changed during the transition. This is because the transition has not been completed yet. Therefore, if you want to check the resolution field after it has been set/changed during the transition, you need to use the transientVars variable of the validate method in your Validator class.

 

Issue issue = (Issue) transientVars.get("issue");

I hope it helps!

Suggest an answer

Log in or Sign up to answer