Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner Behavior - If status any of [X, Y, Z], make read-only and display error Edited

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.

1 answer

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Bitbucket Smart Commits vs. Genius Commits - What's the difference?

If you already heard about Smart Commits in Bitbucket, know that you just stumbled upon something even better (and smarter!): Genius Commits by Better DevOps Automation for Jira Data Center (+ Server...

106 views 0 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you