Mark assignee as required when specific security level is set

Hi

I'm trying to set up a behaviour in scriptrunner which marks the field assignee as required when the security level has been changed to a specific one.

I've added the field Security Level to my behaviour and mapped it accordingly to our projects and issue types. I've also added a serverside script:

def childField = getFieldById("assignee")
def parentField = getFieldById(getFieldChanged())
def selectedOption = parentField.getValue() as String
 
if(selectedOption == "Autor, Bearbeiter & Beobachter")
{
  childField.setRequired(true)
}
else
{
  childField.setRequired(false)
}

image2016-8-25 16:14:28.png

However, the field is not marked as required when I set the security level.

Can somebody help me here?

Thanks and best regards

Marius

1 answer

1 accepted

The values of the Security Level field have their own manager that you'll need to use. The value that's coming back from parentField.getValue() is basically a numeric ID in string form.

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours
def childField = getFieldById("assignee")
def parentField = getFieldById(getFieldChanged())
def selectedOption = parentField.getValue()

def issueSecurityLevelManager = ComponentAccessor.getIssueSecurityLevelManager()

def level = issueSecurityLevelManager.getIssueSecurityLevelsByName("Autor, Bearbeiter & Beobachter")

if (selectedOption && level) {
    if(selectedOption == level[0].id?.toString())
    {
        childField.setRequired(true)
    }
    else
    {
        childField.setRequired(false)
    }
}

Okay, all clear smile Thanks for your help. It works like a charm.

Best regards

Marius

 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

85 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you