Forums

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

Scriptrunner - Read only field on initialisation based on another custom field value

Hunter1428
Contributor
September 9, 2020

Hey all,

I have been trying to set a field to read only if another custom field equals a specific value.

What I have: (I'm new to groovy so be nice :P)

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def resultsType = getFieldById("customfield_12051")
def archive = getFieldById("customfield_12155")

if (resultsType.getValue() == 'Direct')
{
archive.setReadOnly(true)
}else{
archive.setReadOnly(false)
}

Got it working with a server side script but it won't work on initialisation. I'm sure I read somewhere that on initialisation custom field values cannot be read?

Thanks

 

1 answer

0 votes
Najjar _Innovura_
Atlassian Partner
September 9, 2020

Hi @Hunter1428 

Welcome to the groovy world where everything is nearly possible !

Just couple of question to better understand the issue here:

  • Are you using this behavior script on Jira Service desk portal?
  • What is the type of customfield_12051 (radio, select, text) ? 
Hunter1428
Contributor
September 9, 2020

Hey @Najjar _Innovura_ 

Thanks for such a super fast response!

Here are my answers to your questions :)

  1. Using it on Jira Core/Sever (Not Service Desk)
  2. Single Select List
Najjar _Innovura_
Atlassian Partner
September 9, 2020
Try this

if (resultsType.getValue().toString() == 'Direct')
{
archive.setReadOnly(true)
}else{
archive.setReadOnly(false)
}
Hunter1428
Contributor
September 10, 2020

Still nothing, it works on the Server side script but not on the Initialiser :(

Suggest an answer

Log in or Sign up to answer