Hi,
I'm trying to set Fix version field mandatory at create issue screen based on the selected value of single select drop down (Requirement Type) using behaviors.
The fix version field is not set as mandatory at the issue creation field, but in logs I can see the field is set mandatory after the issue creation event is fired.
Below is the script I'm using.
import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.project.version.VersionManager
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
@BaseScript FieldBehaviours fieldBehaviours
def customFieldManager = ComponentAccessor.getCustomFieldManager()
VersionManager versionManager = ComponentAccessor.versionManager
def requirementType = getFieldByName('Requirement Type')
def fixVersionsField = getFieldById('fixversions')
def requirementTypeValue = requirementType.getValue() as String
if(requirementTypeValue)
{
if (requirementTypeValue.equals('A')) {
log.warn("Error thrown")
fixVersionsField.setRequired(true)
throw new InvalidInputException("Fix version field is required")
}
else{
fixVersionsField.setRequired(false)
}
}
Could someone please point out what I'm missing or how can the fix version field be set mandatory before the issue creation is event is fired.
Thanks
Hi @Manjupriya T and welcome,
put the following code to Requirement Type field:
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript
def requirementType = getFieldById(getFieldChanged());
def fixVersionsField = getFieldById('fixversions')
String requirementTypeValue = requirementType.getValue();
if ("A".equalsIgnoreCase(requirementTypeValue)) {
log.warn("Error thrown");
fixVersionsField.setRequired(true);
}
else{
fixVersionsField.setRequired(false);
}
Please let me know if it works,
Fabio
Hi @Fabio Racobaldo _Herzum_ ,
Thanks for getting back on this issue.
I have tried out your script, but that does not help. Fix version field is not set as mandatory though "Requirement Type" field value selected is "A".
Is there specific function that should be used to make the field mandatory before the issue created event fires?
Thanks,
Manjupriya T
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Manjupriya T ,
are you sure that you setup behaviour correctly with a correct mapping to your project/issue type and adding my code to Requirement Type field? Please could you share behaviour configuration screenshot?
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Fabio Racobaldo _Herzum_ ,
I have the correct mappings and the script have been added to the correct field.
Please find the screenshots.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What field type is RequirementType?
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.
Hey @Manjupriya T ,
try this :
def requirementType = getFieldById(getFieldChanged());
def fixVersionsField = getFieldById("fixVersions")
String requirementTypeValue = requirementType.getValue();
if("A".equalsIgnoreCase(requirementTypeValue)) {
fixVersionsField.setRequired(true);
} else{
fixVersionsField.setRequired(false);
}
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.
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.