Disable changing of a field

Joe Harmon
Contributor
March 2, 2023

I am trying to find out if I can disable the editing of a field when it is in a particular status.  I have scriptrunner and wanted to know if this can be done with the scriptrunner behaviors.

2 answers

1 accepted

0 votes
Answer accepted
Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2023
I'm doing something similar with one of my own custom fields. You could update the 'if statement' to access the issue's status instead of its project key. 
import com.atlassian.jira.component.ComponentAccessor

def field = getFieldByName("Priority Number")

def customField = customFieldManager.getCustomFieldObject(field.getFieldId())

def fieldConfig = customField.getRelevantConfig(getIssueContext())




if (issueContext.projectObject.key != "INNP"){

    field.setReadOnly(true)

}
Joe Harmon
Contributor
March 6, 2023

You don't know what the syntax for that would be do you?

Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2023


def issueStatus = issue.getStatus().getName()

See what that gets you. 

VIA: https://community.atlassian.com/t5/Jira-Software-questions/Scriptrunner-listener-get-current-issue-data/qaq-p/1931114

Joe Harmon
Contributor
March 6, 2023

Thanks, I'll try it out

Joe Harmon
Contributor
March 6, 2023

New to scripting.  Something like this @Judah ?

 

import com.atlassian.jira.component.ComponentAccessor

def field = getFieldByName("Original Due Date")

def customField = customFieldManager.getCustomFieldObject(field.getFieldId())

def fieldConfig = customField.getRelevantConfig(getIssueContext())


def issueStatus = issue.getStatus().getName()




if (issueStatus = “Development”){

    field.setReadOnly(true)

}

Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 7, 2023

@Joe Harmon I tweaked yours a little and got the below to work on my instance. 

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()

def issue = underlyingIssue

def field = getFieldByName("Story Points")

def issueStatus = issue.getStatus().getName()

if (issueStatus == "Ready for Development"){

    field.setReadOnly(true)

}
Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 7, 2023

You will need to change the field name and the status name, but that should do the trick

Joe Harmon
Contributor
March 8, 2023

Thanks, I assume you are using a behavior for this?

Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 8, 2023

That is correct

Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 8, 2023

Please let me know if it works

Joe Harmon
Contributor
March 8, 2023

Yes that worked, thanks for all your help.

Like Judah likes this
0 votes
Kristján Geir Mathiesen
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 2, 2023

Hi @Joe Harmon 

This article here does not say how to do it with Scriptrunner but might give you some ideas how this can be achieved without Scriptrunner.

HTH,
KGM

Joe Harmon
Contributor
March 3, 2023

Yeah those aren't going to work for me, but thanks for the suggestion.  I know there is a way to set a field to read only with scriptrunner behaviors, but trying to find good script examples of doing that during while only in a certain status.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events