Trying to pick ScriptRunner back up for the organization and I'm running into some problems. Trying to read the issue status and make a field read-only... but I want to tell users why it's read-only, hence using a script rather than the OOTB read-only marker.
I've read almost every community article that mentions this, and even did a direct copy/paste from https://scriptrunner.adaptavist.com/6.9.1/jira/recipes/behaviours/scripted-conditions.html ... It either enforces ALL the time or NONE of the time. The same is true of the in-line edit... It's always locked, no matter what group I put in there.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.config.StatusManager
StatusManager statusManager = ComponentAccessor.getComponentOfType(StatusManager.class)
// Get the current user
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// Get the changed field
def exampleField = getFieldById(getFieldChanged())
if (ComponentAccessor.getGroupManager().getGroupsForUser(currentUser)?.find { it.name == "UI-fragment-users" }) {
exampleField.setAllowInlineEdit(true)
} else {
exampleField.setAllowInlineEdit(false)
}
if (statusManager.getStatuses()*.getName() != ["To Do", "Analysis", "Intake Agenda", "Intake Meeting", "Prioritization"]) {
exampleField.setError("To maintain data integrity, this field is locked for edits after Prioritization.")
exampleField.setReadOnly(true)
} else {
exampleField.clearError()
exampleField.setReadOnly(false)
}
I've also tried
issue.getStatus().getName()
and
underlyingIssue.getStatus().name
But I can't seem to get it to work.
Hi Lacey
If you are using
def exampleField = getFieldById(getFieldChanged())
then you most likely have this script applied to a field directly within the behaviour configuration.
What field is this "exampleField"?
Generally, the status of an issue does not change while in the form window that behaviours work on, so it does not really make sense to have this script on a field and it should really be in the behaviour initialiser script area.
You could try a script like this as an initialiser.
def myField = getFieldByName("TextFieldB")
if(!underlyingIssue){
// if there is no underlyingIssue then you are on the create screen and there is nothing to get the status fro,
return
}
def currentStatus = underlyingIssue.status.name
def testStatusList = ["In Progress", "Done"]
if(currentStatus in testStatusList){
log.warn("status ${currentStatus} found in ${testStatusList}")
myField.setReadOnly(true)
myField.setDescription("To maintain data integrity, this field is locked for edits after Prioritization.")
}else{
myField.setReadOnly(false)
myField.setDescription("")
}
Regards
Matthew
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.