Validation of versions select custom field

Alon Erez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 6, 2017

Hi,

I want to add a validation when creating an issue, the definition is to check one field (called ‘Found In’) which is a Select List (single choice) custom field, and if the value in it is A or B then check if another field has a value. The second field is a Version Picker (single version), called ‘Release’.

 I tried using the script runner simple script validation, but I don’t know how to get the value of the Release field, and also how to ask for the A OR B. checking just for one works.

 Can someone help with the needed validation code ?

Thanks,
Alon

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 6, 2017

Hello,

It could be like this

if (ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("single select").getValue(issue).toString().equals("A") || ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("single select").getValue(issue).toString().equals("B")) {

if (ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Release").getValue(issue).size() > 0) {

return true;

} else {

return false;

}

} else {

return true;

}
Alon Erez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 10, 2017

Thank you for your answer.

It didn't work as you wrote, but it pointed me in the right direction.

I think the problem was getting the value for the version picker field.

Here is what I ended up with:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
// get "Release" field
CustomField customField = customFieldManager.getCustomFieldObject("customfield_11434");
def currentValue = issue.getCustomFieldValue(customField)

// if (ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("single select").getValue(issue).toString().equals("A") || ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("single select").getValue(issue).toString().equals("B")) {
if ((cfValues['single select']?.value == 'A' ) || (cfValues['single select']?.value == 'B' )) {
if (currentValue)
{
return true ;
}
else{
return false;
}
}
else {
return true;
}
TAGS
AUG Leaders

Atlassian Community Events