Hi.
I am trying to set few custom fields Visible and Mandatory if user select Component = "Financial Shared Services" in issue Create / Edit screen. I tried with below two scripts but it's not working. It's jumping to else part directly. Can you please help what am I missing here.
Script 1 :
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def EmployeeHrs = getFieldByName("Total Number of Employee Hours")
def component = getFieldByName("Component/s")
def componentV = component.getValue())
if (componentV.toString().contains("Financial Shared Services")) {
EmployeeHrs.setRequired(true);
EmployeeHrs.setHidden(false);
}
else {
EmployeeHrs.setRequired(false);
EmployeeHrs.setHidden(true);
}
Script 2 :
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def EmployeeHrs = getFieldByName("Total Number of Employee Hours")
def component = getFieldByName("Component/s")
def componentV = component.getValue()
if (componentV == "Financial Shared Services") {
EmployeeHrs.setRequired(true);
EmployeeHrs.setHidden(false);
}
else {
EmployeeHrs.setRequired(false);
EmployeeHrs.setHidden(true);
}
Thanks,
Hardik
Hello @Hardik Parekh
You should get system fields by id, not name. Try like this
def EmployeeHrs = getFieldByName("Total Number of Employee Hours")
def component = getFieldById("components")
def componentV = component.getValue()
if (componentV.toString().contains("Financial Shared Services")) {
EmployeeHrs.setRequired(true);
EmployeeHrs.setHidden(false);
}
else {
EmployeeHrs.setRequired(false);
EmployeeHrs.setHidden(true);
}
And place this code attached to Components field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for help @Mark Markov . It worked.
I hope this will work for Date, UserPicker and Multi-select field as well.
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.