Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,363,572
Community Members
 
Community Events
168
Community Groups

Scriptrunner - Limit results on issue picker based on current issue organization

Hello all

I need to write a scripted field or behaviour (not quite sure) where I have a Issue Picker Custom Field for a specific project where I need it to behave like described below:

I am working on an specific issue, let´s say, PROJECT-1 and this issue has an organization associated named CLIENT1. This project has a custom field called "Associated Problem" where I must limit the results only to bring other issues from this project that the organization is the same, i.e CLIENT1 and that status are "Open" and "In Progress"

This logic must follow for other issues from this project having other organizations.. CLIENT2... CLIENT3.... etc.
I am able to limit by status using simple JQL but I am quite inexperient on scripting and I am not finding a easy solution for matching only results from same organization as the current issue.

Can you people give me some light into this?

1 answer

1 accepted

For anyone looking for a similar solution, I have managed to work that out.

In short, I have created a Issue Picker Field called "Issue Associada" and on Behaviours I created an new entry associated to this field.

This field will have a dynamic JQL which will look for current issue custom field called "Organização" (not the same as system Organization) and will search for results

My script, although not elegant, is working fine.

 

import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue;

def customFieldManager = ComponentAccessor.getCustomFieldManager()

//Here I will define variable issuePicker to get Custom Field "Issue Associada"

def issuePicker = getFieldByName("Issue Associada")

//Here I will get Custom Field value from custom field "Organização" and set it on a variable. This value comes from  from the issue I am editing the Issue Picker field.

def Value = customFieldManager.getCustomFieldObjectByName("Organização")
def orgValue = underlyingIssue.getCustomFieldValue(Value)

//Below I am running a query JQL looking for specific conditions including my new variable

issuePicker.setConfigParam('currentJql', /project = "Implantação" and status = "Em Andamento" and Organização = "$orgValue"/)

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events