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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,440
Community Members
 
Community Events
176
Community Groups

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

0 votes

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

Atlassian Community Events