Im trying to create a workflow "simple script validator" for a transition. Trying to set this up for Original Estimate and Story Points. Basically require one or the other custom field. If one isnt filled out require the other and vise versus. Im not a developer but i have been able to get some insight from other examples ive read online.
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
def CustomFieldManager = ComponentAccessor.getCustomFieldManager();
def CustomFieldValue1 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Original Estimate"));
if(CustomFieldValue1 == null) {
def CustomFieldValue2 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Story Points"));
if(CustomFieldValue2 == null){
def invalidInputException = new InvalidInputException("Original Estimate is required");
}
}
Hi Tim,
Something like this should do the trick:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.opensymphony.workflow.InvalidInputException
Issue issue = issue
if (!issue.getOriginalEstimate()) {
throw new InvalidInputException("Story Points is required!")
} else if (!getCustomFieldValue(issue, "Story Points")) {
throw new InvalidInputException("Original Estimate is required!")
}
return true
Object getCustomFieldValue(Issue issue, String fieldName) {
CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(fieldName)
return issue.getCustomFieldValue(customField)
}
Thank you so much Ivan. I tested the code out and it is now requiring both fields to be filled out before it allows it to be transitioned. I needed it to be one or the other though. Need it to require Story Points if the custom field Original Estimate isnt filled out. And the same the other direction make Original Estimate required if Story Points isnt filled in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Was finally able to get this to work with the following script. Thanks Ivan for getting me started. This actually works.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.Issue import com.opensymphony.workflow.InvalidInputException def Object getCustomFieldValue(Issue issue, String fieldName) { CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(fieldName) return issue.getCustomFieldValue(customField) } def Object storyPoints = getCustomFieldValue(issue, "Story Points"); def Object originalEstimate = issue.originalEstimate; return !(storyPoints == null && originalEstimate == null)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.