Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to set fix version field mandatory based on single select option value using behaviors

Manjupriya T June 14, 2023

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

1 answer

1 accepted

1 vote
Answer accepted
Fabio Racobaldo _Herzum_
Community Champion
June 15, 2023

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

Manjupriya T June 15, 2023

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

Fabio Racobaldo _Herzum_
Community Champion
June 15, 2023

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

Manjupriya T June 15, 2023

Hi @Fabio Racobaldo _Herzum_ ,

I have the correct mappings and the script have been added to the correct field.

Please find the screenshots.requirement type.PNGserver side script.PNG

Thanks

Fabio Racobaldo _Herzum_
Community Champion
June 15, 2023

What field type is RequirementType?

Manjupriya T June 15, 2023

@Fabio Racobaldo _Herzum_ ,

It's Single select drop down type.

Thanks,

Manjupriya T

Fabio Racobaldo _Herzum_
Community Champion
June 16, 2023

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);
}
Manjupriya T June 16, 2023

Hi @Fabio Racobaldo _Herzum_ ,

It's working now.

Thanks for your help here.

Thanks,

Manjupriya T

Fabio Racobaldo _Herzum_
Community Champion
June 16, 2023

@Manjupriya T I'm happy for that. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events