Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner make a field read-only after status

mosinski
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 16, 2021

I need to make a field read-only after transition to a status and above. To give you an inside, we have a flow going like(simplified):

1) Scope

2) Ready for dev

3) Dev

4)...

And after transition to Ready for dev I want a custom field to be set as read-only to prevent from any changes. I have tried to use below code but during testing it is not preventing from editing the field.

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FormField

FormField PlannedReleaseDate = getFieldById("23914")
def PlannedReleaseDateValue = (Date) PlannedReleaseDate.getValue()

def status = getFieldByName("status").getValue()

if( Arrays.asList("Ready for dev","Dev","UAT").contains(status) )

if (PlannedReleaseDateValue != null) {
PlannedReleaseDate.setReadOnly(true)
}

else {
PlannedReleaseDate.setReadOnly(false)
}

 

3 answers

1 vote
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
September 17, 2021

Hi @mosinski I can see that condition

if( Arrays.asList("Ready for dev","Dev","UAT").contains(status) )

is not OK, you need to use {}  to use the condition for block of the code, so it should be probably

if( Arrays.asList("Ready for dev","Dev","UAT").contains(status) ){

if (PlannedReleaseDateValue != null) {
PlannedReleaseDate.setReadOnly(true)
} else {
PlannedReleaseDate.setReadOnly(false)
}
}
1 vote
Dirk Ronsmans
Community Champion
September 16, 2021

Hey @mosinski ,

Not sure if it's needed but my mind immediatly jumps to your 

FormField PlannedReleaseDate = getFieldById("23914")

could you change that to 

FormField PlannedReleaseDate = getFieldById("customfield_23914")

and try again?

 

https://docs.adaptavist.com/sr4js/latest/features/behaviours/api-quick-reference

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
September 16, 2021

@mosinski and it is a good practice to check the atlassia-jira.log file if something does not work :).

0 votes
mosinski
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 17, 2021

Thank you for the answers. I have changed the ID of customfield but still I am able to change the date. Where can I find the log file?

Suggest an answer

Log in or Sign up to answer