You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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
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;
}
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;
}
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.