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 null
HERE 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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"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"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How would an error handler look if I wanted to add it to this script?
return null
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.project.Project
import java.text.SimpleDateFormat
import groovy.json.JsonSlurper
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.project.property.ProjectPropertyService
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
def 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.jiraAuthenticationContext
ProjectPropertyService projectPropertyService = ComponentAccessor.getComponentOfType(ProjectPropertyService.class)
UserManager userManager = ComponentAccessor.userManager
def user = userManager.getUserByName(jiraAuthenticationContext.getLoggedInUser()?.name)
def value = projectPropertyService.getProperty(user, projectId, key)?.entityProperty?.value?.value
if(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 ?: ''
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Howard Nedd ,
Sadly, I don't think there is a possibility to hide/disable the scripted field instead of deleting them.
-Kevin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
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.