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)
}
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)
}
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@mosinski and it is a good practice to check the atlassia-jira.log file if something does not work :).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.