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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Tuesday in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

118 views 0 4
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