Forums

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

Scriptrunner Behaviour not to run on Create Issue screen

Martin Haagen
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!
October 18, 2017 edited

Use case: The customer wants a number of fields set to read-only when issues have certain statuses.

My solution: I have created a Scriptrunner Behaviour with an Initialiser script as follows:

if (getAction()?.id == 1) { //Do not run script on Create action
  log.warn('ACTION = CREATE')
  return
}

def lockStatuses = ['status1','status2','status3'] //Statuses where fields should be read-only
def issueStatus = underlyingIssue.status.name.toLowerCase() //Status of the undelying issue
    
if (!lockStatuses.contains(issueStatus)) {
  log.warn('STATUS WILL NOT MAKE FIELDS READ-ONLY')
  return
}

else {
  log.warn('SETTING FIELDS READ-ONLY!')
  def lockFields = ['customField1','customField2','customField3'] //Fields that should be set to read-only

  lockFields.each { lockField ->
    getFieldByName(lockField).setReadOnly(true)
  }
 
  getFieldById("summary").setReadOnly(true)
}

This works fine on Edit- and Transition screens.

My problem: If I first view an issue that has one of the above statuses, and then press the "Create" button, the above fields is being set to read only on the Create screen, despite the first "if" in the script.
If I Cancel out of the Create screen and press the "Create" button once again, the fields are now writable. The issue seems to only occur directly after opening av issue, or after previewing it on boards.

Do anyone have suggestions on what I should try next?

1 answer

1 accepted

3 votes
Answer accepted
Stephen Cheesley _Adaptavist_
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.
October 23, 2017

Hi Martin,

Try switching out your first if statement for the following:

if (getActionName() in ["Create Issue", "Create"]) {
return
}

 I've found when doing this you need to take into account "Create" and "Create Issue"

Hope this helps!

Steve

gabe vid May 16, 2019

That works in a initializer, but not in a server-side script.

Is there a way to do that in server-side script ?

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, likes for trees, atlassian community, social impact, tree planting campaign, community kudos, atlassian giving, environmental impact, sustainability, likes for good, atlassian social responsibility, community challenge

Make every click count—help us plant 50,000 trees! 🌳

Want to make your everyday Community actions directly contribute to reforestation? The Atlassian Community can achieve this goal by liking a post, attending an ACE, sending your peers kudos, and so much more!

Help us plant more trees
AUG Leaders

Atlassian Community Events