Is it possible to make a custom field mandatory ONLY when another customer field has not been populated (NULL) on a screen.This will happen on the create transition and i have no idea were to start!
You should start with ScriptRunner behaviours. You can find more info here:
https://scriptrunner.adaptavist.com/5.3.0/jira/behaviours-overview.html
You would need to add the custom field which influences the required behaviour of another custom field and write a script for the field.
The script would look something like this
def field1 = getFieldById(getFieldChanged())def field2 = getFieldByName("customFieldName")if (field1.getValue() == "your value") { field2.setRequired(true)} else {field2.setRequired(false)}
I did not check if the script works, but it s the idea.
In my opinion, it is better to use the validator
import com.atlassian.jira.component.ComponentAccessorimport com.opensymphony.workflow.InvalidInputExceptiondef customFieldManager = ComponentAccessor.getCustomFieldManager();def CustomFieldValue1 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("name1"));if(CustomFieldValue1 == null) { def CustomFieldValue2 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("name2")); if(CustomFieldValue2 == null){ invalidInputException = new InvalidInputException("name2 is mandatory when name1 is null"); }}
Worked perfect thanks Neta. Problem im having now is it works when i create the case, but when i create another case it doesnt?
Once ive published the modified workflows its only lasting one creation if that makes sense?
You added another if case and it does not work? Can you send the script?
So i did a validator on the create transition (Script Validator)....
import com.atlassian.jira.component.ComponentAccessorimport com.opensymphony.workflow.InvalidInputException
def customFieldManager = ComponentAccessor.getCustomFieldManager();def CustomFieldValue1 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Retailer ID List"));
if(CustomFieldValue1 == null) {def CustomFieldValue2 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Retailer ID"));if(CustomFieldValue2 == null){invalidInputException = new InvalidInputException("Retailer ID is mandatory when Retailer ID List is not populated");}
}
It looks like you're new here. Sign in or register to get started.