Mark assignee as required when specific security level is set

PFS August 25, 2016

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

2 votes
Answer accepted
Jonny Carter
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.
August 25, 2016

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)
    }
}
PFS August 25, 2016

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
TAGS
AUG Leaders

Atlassian Community Events