Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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.
Dec 06, 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.
Dec 06, 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.
Dec 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