Filtering issues in Behaviours

Hi all,

I have a workflow with screens on Start progress and Resolve and two issue types (Incident and Service request) linked with this workflow. 
On these screens there is a field "Incident affected" which is not needed for Service request issues. 
Now I want to hide this field with "Behaviours" for all issues with Service request issue type and for Incidents, if priority is lower than Medium. current variants in conditions are inappropriate for this case.

maybe there is a way to make an advanced searching issues with jql in Behaviours?

1 answer

1 accepted

2 votes

You can achieve this by using the underlyingIssue binding in an initialiser script for the behaviour like below:

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

@BaseScript FieldBehaviours fieldBehaviours

// this is issue create and we have no underlying issue yet
if (! underlyingIssue) {
    return
}

def issueTypeName = underlyingIssue.getIssueTypeObject().getName()
def priortityManager = ComponentAccessor.getComponent(PriorityManager)

// get medium priority
def mediumPriority = priortityManager.getPriorities().find { priority ->
    priority.name == "Medium"
}

// the higher the priority sequence number the lower the priority
if (issueTypeName == "Service request" || (issueTypeName == "Incident" && underlyingIssue.priorityObject.sequence > mediumPriority)) {
    def incidentField = getFieldByName("Incident affected")

    incidentField.setHidden(true)
}

JQL is not really well suited to this as you would need to search through all the issues when you already have the issue available here, its not very feasible as it needs to run every time someone views a page.

Hope this helps,
Adam 

Thanks, Adam! 

it must be added to "Add serverside script", isn't it? 

can we set some value for "Incident affected" (it is a single choise select list) here in this script or it have to be done from the workflow transition? 

Yes thats correct, it should be added to the initialiser like in this example: https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html#_setting_a_default_description

Theres an example for setting a default value for the select list here: https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html#_setting_a_default_description

But if you don't want the user to edit this default selected value you also need to add:

incidentField.setReadOnly(true)

 

 

 

added this lines (needed to set a value by default when it's hidden), it works correctly.

thanks a lot! 

def IncidentAffected = getFieldByName("Incident Affected")
int defaultVal = 10404 //single user
IncidentAffected.setFormValue(defaultVal)

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...

134 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