I would like to disable a scripted field instead of deleting it. Is the only way to disable it by deleting the entire script, or getting rid of it in screens /issuetypes etc? Seems a bit cumbersome.
Hi @Howard Nedd , did you try to return null on the first row of your script? It could look like
return nullHERE IS YOUR CODE
The script will be always executed so it can have performance impacts.
If you do not want the script to be executed you will need to remove the field from all the Screens -> set them back when you need it.
"return null" on the first line is the easiest way to "disable" a scripted field.
But I think there is a deeper question here.
Why are you trying to "disable" a scripted field? What do you get from "disable" that is better than "delete"?
Hi @Howard Nedd ,
Sadly, I don't think there is a possibility to hide/disable the scripted field instead of deleting them.
-Kevin
Hi Kevin, Thank you for getting back at me. I have searched the web and it seems there is no way to simply disable it to do your test, so the remaining option is documenting the script and delete it for now.
@Howard Nedd Yea, unfortunately, that's the only option for now.
-Kevin.
Hi Martin,
Thank you.
This does not disable the scripted fields right? It will just make it return nothing, right?
So I believe the only option is getting rid of the scripted fields on the screens it is added to.
Hi @Howard Nedd , yeah, it won't disable it, but if a null value is returned, the field should not be displayed on view screen...
Hi Nic, valid question.
The fields don't seem to be used right now. They have been added to 2 screens of our entire config and those screens are part of projects that no longer will be used but to make sure I dont mess things up I wanted to disable these fields.The script itself was also giving out errors (seems the script did not have an error handler so whenever the script resulted in "Not True" it gave a error).
So if we do decide to keep this error I will add a the error handler to it but for now I will add return null to the scripts and eventually get rid of them if they are not needed.
How would an error handler look if I wanted to add it to this script?
return null import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.project.Projectimport java.text.SimpleDateFormatimport groovy.json.JsonSlurperimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.bc.project.property.ProjectPropertyServiceimport com.atlassian.jira.security.JiraAuthenticationContextimport com.atlassian.crowd.embedded.api.Userimport com.atlassian.jira.user.ApplicationUserimport com.atlassian.jira.user.util.UserManagerdef customFieldManager = ComponentAccessor.getCustomFieldManager()def sprintCf = customFieldManager.getCustomFieldObject(10000)def sprints = issue.getCustomFieldValue(sprintCf)//def sprint = sprints.find { !it.isClosed() }//if (sprint == null)def sprint = sprints?.last()getSprintEndDate(issue.projectObject, sprint)Date getSprintEndDate(Project project, def sprint) {if (sprint) {if(sprint.endDate){return sprint.endDate.toDate()} else {def projectParams = getProjectParameters(project.id, 'sprint_settings')def sprintSettings = new SprintSettings(projectParams)String endDate = sprintSettings.getEndDate(sprint.id)if(endDate) {return new SimpleDateFormat('yy-MM-dd').parse(endDate)}}}return null;}Map getProjectParameters(Long projectId, def key) {try {JiraAuthenticationContext jiraAuthenticationContext = ComponentAccessor.jiraAuthenticationContextProjectPropertyService projectPropertyService = ComponentAccessor.getComponentOfType(ProjectPropertyService.class)UserManager userManager = ComponentAccessor.userManagerdef user = userManager.getUserByName(jiraAuthenticationContext.getLoggedInUser()?.name)def value = projectPropertyService.getProperty(user, projectId, key)?.entityProperty?.value?.valueif(value) {def ret = new JsonSlurper().parseText(value)return ret}return [:]} catch(Exception e) {return [:]}}class SprintSettings {private List settings = []def SprintSettings(Map jsonParameters) {jsonParameters.settings.each {settings << [sprintId: it.sprint_id,capacity: it.capacity,startDate: it.start_date,endDate: it.end_date]}}List getSettings() {return settings}boolean contains(Long sprintId) {return contains(sprintId as String)}boolean contains(String sprintId) {return (settings.find { it.sprintId == sprintId } != null)}def getCapacity(def sprintId) {return settings.find { it.sprintId == sprintId as String }?.capacity ?: 0}def getStartDate(def sprintId) {return settings.find { it.sprintId == sprintId as String }?.startDate ?: ''}def getEndDate(def sprintId) {return settings.find { it.sprintId == sprintId as String }?.endDate ?: ''}}
Please bear in mind that removing the script field from screens will just hide the field from users but it doesn't ensure the script field won't be executed.
The script field is still executed when it's used as a column in the Issue Navigator, in JQL and other queries (board quick filters etc.), via exports, REST API calls (where fields are not explicitly specified) and probably (not sure) when an issue is re-indexed.
It looks like you're new here. Sign in or register to get started.