Filtering issues in Behaviours

SaidAslan July 27, 2016

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
Answer accepted
adammarkham
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.
July 28, 2016

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 

SaidAslan July 28, 2016

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? 

adammarkham
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.
July 28, 2016

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)

 

 

 

SaidAslan July 28, 2016

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

Atlassian Community Events