Hello everyone,
I have set a server-side script on one of the fields.(Service Portal mapping)
And I'm toggling setHidden between true and false for rest of the fields based on the server-side script field.
Now, the issue is when I use setFieldOptions on one of the other fields, setHidden fails to update the visibility. The visibility state of the field takes earlier state before setFieldOptions.
When I inspected the page, the script actually does it's job but fails to update the CSS Style, Display of the field-group.
Any thoughts on how to fix it?
// Classes
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.config.FieldConfig
// Component Managers
def cFieldMgr = ComponentAccessor.getCustomFieldManager()
def optionsMgr = ComponentAccessor.getOptionsManager()
// Custom Fields
def cBusinessJustification = cFieldMgr.getCustomFieldObject(Long)
FieldConfig fieldConfig = cBusinessJustification.getRelevantConfig(issueContext)
def options
// Get all form fields
def formField_summary = getFieldById("summary")
def formField_RequestType = getFieldById("customfield_XXXX")
def formField_BusinessJustification = getFieldById("customfield_XXXX")
def formField_BusinessTitle = getFieldById("customfield_XXXX")
def formField_StartDate = getFieldById("customfield_XXXX")
def formField_LatestHireDate = getFieldById("customfield_XXXX")
def formField_JobCode = getFieldById("customfield_XXXX")
def formField_WorkerType = getFieldById("customfield_XXXX")
def formField_DepartmentCode = getFieldById("customfield_XXXX")
def formField_NotesComments = getFieldById("customfield_XXXX")
// Hide all the fields except Request Type
formField_BusinessJustification.setHidden(true)
formField_BusinessTitle.setHidden(true)
formField_StartDate.setHidden(true)
formField_LatestHireDate.setHidden(true)
formField_JobCode.setHidden(true)
formField_WorkerType.setHidden(true)
formField_DepartmentCode.setHidden(true)
formField_NotesComments.setHidden(true)
// Copy the Request Type to Summary
def value = 'Workday: ' + formField_RequestType.getValue()
formField_summary.setFormValue(value)
// Request Type: Create Position
if (formField_RequestType.getValue().toString() == 'Create Position') {
// Make the relevant fields visible
formField_BusinessJustification.setHidden(false)
formField_BusinessTitle.setHidden(false)
formField_StartDate.setHidden(false)
formField_LatestHireDate.setHidden(false)
formField_JobCode.setHidden(false)
formField_WorkerType.setHidden(false)
formField_DepartmentCode.setHidden(false)
formField_NotesComments.setHidden(false)
// Make the appropriate fields mandatory
formField_BusinessJustification.setRequired(true)
formField_BusinessTitle.setRequired(true)
formField_StartDate.setRequired(true)
formField_LatestHireDate.setRequired(true)
formField_JobCode.setRequired(true)
formField_WorkerType.setRequired(true)
formField_DepartmentCode.setRequired(true)
}
else if (formField_RequestType.getValue().toString() == 'Create Job Requisition'){
options = optionsMgr.getOptions(fieldConfig).iterator().findAll {
it.toString() in ['Hire -> Additional Headcount',
'Hire -> Backfill'] }
formField_BusinessJustification.setFieldOptions(options)
formField_BusinessJustification.setHidden(true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
// Classes
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.config.FieldConfig
// Component Managers
def cFieldMgr = ComponentAccessor.getCustomFieldManager()
def optionsMgr = ComponentAccessor.getOptionsManager()
// Custom Fields
def cBusinessJustification = cFieldMgr.getCustomFieldObject(Long)
FieldConfig fieldConfig = cBusinessJustification.getRelevantConfig(issueContext)
def options
// Get all form fields
def formField_summary = getFieldById("summary")
def formField_RequestType = getFieldById("customfield_XXXX")
def formField_BusinessJustification = getFieldById("customfield_XXXX")
def formField_BusinessTitle = getFieldById("customfield_XXXX")
def formField_StartDate = getFieldById("customfield_XXXX")
def formField_LatestHireDate = getFieldById("customfield_XXXX")
def formField_JobCode = getFieldById("customfield_XXXX")
def formField_WorkerType = getFieldById("customfield_XXXX")
def formField_DepartmentCode = getFieldById("customfield_XXXX")
def formField_NotesComments = getFieldById("customfield_XXXX")
// Hide all the fields except Request Type
formField_BusinessJustification.setHidden(true)
formField_BusinessTitle.setHidden(true)
formField_StartDate.setHidden(true)
formField_LatestHireDate.setHidden(true)
formField_JobCode.setHidden(true)
formField_WorkerType.setHidden(true)
formField_DepartmentCode.setHidden(true)
formField_NotesComments.setHidden(true)
// Copy the Request Type to Summary
def value = 'Workday: ' + formField_RequestType.getValue()
formField_summary.setFormValue(value)
// Request Type: Create Position
if (formField_RequestType.getValue().toString() == 'Create Position') {
// Make the relevant fields visible
formField_BusinessJustification.setHidden(false)
formField_BusinessTitle.setHidden(false)
formField_StartDate.setHidden(false)
formField_LatestHireDate.setHidden(false)
formField_JobCode.setHidden(false)
formField_WorkerType.setHidden(false)
formField_DepartmentCode.setHidden(false)
formField_NotesComments.setHidden(false)
// Make the appropriate fields mandatory
formField_BusinessJustification.setRequired(true)
formField_BusinessTitle.setRequired(true)
formField_StartDate.setRequired(true)
formField_LatestHireDate.setRequired(true)
formField_JobCode.setRequired(true)
formField_WorkerType.setRequired(true)
formField_DepartmentCode.setRequired(true)
}
else if (formField_RequestType.getValue().toString() == 'Create Job Requisition'){
options = optionsMgr.getOptions(fieldConfig).iterator().findAll {
it.toString() in ['Hire -> Additional Headcount',
'Hire -> Backfill'] }
formField_BusinessJustification.setFieldOptions(options)
formField_BusinessJustification.setHidden(true)
}
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.
ok, thank you, and problem is with field "formField_BusinessJustification"?
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.
I think you can't use options in this way, but it should be something like:
options = optionsMgr.getOptions(fieldConfig).iterator()
.findAll({ it.toString() in ['Hire -> Additional Headcount', 'Hire -> Backfill'] }).collectEntries({[ (it.optionId.toString()) : it.value ]})
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
java.lang.object does not have a property optionId
java.lang.object does not have a property value
The field, Business Justification is a radio field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, it is just static code check error, but setting field option is working right? But the problem is that I wrote a script and now I'm experiencing the same behaviour. When setFieldOptions method is used, setHidden does not work on field. I think it must be feature or bug, but I didn't find anything about it in the documentation. I suggest you to create ticket on adaptavist service desk.
BTW my script is:
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def singleSelectField = customFieldManager.getCustomFieldObject(10600L)
def fieldConfig = singleSelectField.getRelevantConfig(issueContext)
def field = getFieldByName("Single select field")
field.setDescription("hokus pokus")
log.error("brrr:")
def options = optionsManager.getOptions(fieldConfig).iterator()
.findAll({ it.value in ['1', '3'] }).collectEntries({[ (it.optionId.toString()) : it.value ]})
field.setHidden(true)
field.setFieldOptions(options)
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.