Hi Atlassian Community, im looking for solution to set Issue security Level based on custom field value.
I find the best way to do this by using ScriptRunner workflow function:
Description:
We have custom filed "Teams".
We have values "Team first"; "Team Second"
We have issue security level, and one of this level which called "Administration Task SL"
Also i find id of this custom field value id of one of parameter "Team first = 11700"
But im new in this scripts and always get an error:
All screen how i try to do this
1) use transition on which i need to change issue security level
2) try to add postfunction from ScriptRunner workflow function (Set Issue security level depending on provided condition)
3) SetName of security level
4) Got issue's in code
Maybe im doing something wrong or not define some values.
Here are my code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.security.IssueSecurityLevelManager
import com.atlassian.jira.issue.security.IssueSecuritySchemeManager
def project = issue.getProjectObject()
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def issueSecuritySchemeManager = ComponentAccessor.getComponent(IssueSecuritySchemeManager)
def issueSecurityLevelManager = ComponentAccessor.getComponent(IssueSecurityLevelManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.issueManager
def cfValue =customFieldManager.getCustomFieldObjectByName("Teams")
if (cfValue == 'Team first') {
issue.setSecurityLevelId(11700)
}
Maybe somebody meet this before? or can help me how to correct define condition?
Or somebody know how to make, becose we need to use one of two issue security level based on custom field. Maybe i need something different?
if (cfValue == 'Team one') {
issue.setSecurityLevelId(null)
} else if (cfValue == 'Team second') {
issue.setSecurityLevelId(secLevel.id)
} else {
//something else
}
Hi to all, I am trying to do a similar thing, I have this code that works, in the sense that it writes in the custom field security level the value taken from the field Group Assignee, group picker. But every time I complete the transition between two states of the workflow, I always find the previous value of the group picker and not the current one, as if I was forgetting to write something to force the update of the issue. Since I'm still a newbie in Script Runner, I'm asking if you can help me to understand where I'm going wrong.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.security.IssueSecurityLevelManager
import com.atlassian.jira.issue.security.IssueSecuritySchemeManager
import com.atlassian.crowd.embedded.impl.ImmutableGroup
def issueSecuritySchemeManager = ComponentAccessor.getComponent(IssueSecuritySchemeManager)
def issueSecurityLevelManager = ComponentAccessor.getComponent(IssueSecurityLevelManager)
def customFieldManager = ComponentAccessor.customFieldManager
// Change it to your Group Picker field name
def groupPicker = customFieldManager.getCustomFieldObjectsByName("Gruppo Assegnatario").first()
def group = (issue.getCustomFieldValue(groupPicker) as ArrayList<ImmutableGroup>).first()
def project = issue.getProjectObject()
def issueSecurityScheme = issueSecuritySchemeManager.getSchemeFor(project)
def securityLevelID = issueSecurityLevelManager.getIssueSecurityLevels(issueSecurityScheme.id).find { it ->
// since the group name is equal to the security level name
it.name == group.name
}?.id
issue.setSecurityLevelId(securityLevelID)
You don't need to explicitly set the security level using 'Set Issue security level depending on provided condition'
Just set the condition and the security level
Add multiple functions with mutually exclusive conditions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tom!
I try this example, few time before, i got next error:
cfValues['Art Team & Position']?.value == '3D Photoreal Characters Team'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
try
cfValues['Group Field']?.name == 'Team First'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
What is the type of custom field you are checking? It will need to match the field object properties
.name works on my server with a Group Single select.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just tested again. On my server, for a simple select list .value works.
cfValues['Select test']?.value == 'One'
The full error message tells you what object is being returned and you can check available getters in the API docs
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
It seems like the error is "Cannot find matching method" because you are using int for ID. But setSecurityLevelId uses long for id. See below link:
If you change it to
issue.setSecurityLevelId(11700L)
that problem should be solved.
Regards,
Elifcan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I try another more simple way it, no error but issue securite doesnt update
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def CC = customFieldManager.getCustomFieldObject("customfield_15001")
def CC_value = issue.getCustomFieldValue(CC).toString()
if (CC_value == '3D Team')
{
issue.setSecurityLevelId(11700L)
}
else if (CC_value == 'ArtTeam')
{
issue.setSecurityLevelId(11702L)
}
Also maybe steps not set up correct?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
see
https://scriptrunner.adaptavist.com/latest/jira/builtin-scripts.html#_set_issue_security
"for the create transition, above the "Creates the issue originally" function"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I change steps, but i look to configuration of field
this field named: Select List (cascading)
I think i have trouble with this(
I think i need use id? not 'some text value' ???
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
before i go digging, did you intend to use a cascading select and are you looking to match the first level value against your team name?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
this will log the cascade fields values. its the weekend now :-) good luck
import com.atlassian.jira.issue.customfields.view.CustomFieldParams
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.impl.CascadingSelectCFType
import org.apache.log4j.Category
log.setLevel(org.apache.log4j.Level.DEBUG)
CustomField cf = customFieldManager.getCustomFieldObjectByName("Cascade test")
Object cfVal = issue.getCustomFieldValue(cf)
log.debug("" +cfVal)
HashMap<String, Option> hashMapEntries = (HashMap<String, Option>) cfVal
log.debug("" + hashMapEntries)
if (hashMapEntries != null) {
Option parent = hashMapEntries.get(CascadingSelectCFType.PARENT_KEY)
Option child = hashMapEntries.get(CascadingSelectCFType.CHILD_KEY)
def first = parent.toString()
def second = child.toString()
log.debug("Cascading values selected: $first - $second")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.