Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using JQL or Issue Filter to set value in scripted field

Matt May 23, 2019

Hello,

 

We have ScriptRunner and Jira Misc Custom Fields plugins installed on our JIRA Server.  

 

I want to be able to set a scripted field value based on either a JQL query, or preferably a range of non-overlapping saved filters.

 

For example:

If issue appears in Filter 1 - Set to "Placeholder"

If issue appears in Filter 2 - Set field status to "To Do"

If issue appears in Filter 3 - Set field status to "In Progress"

If issue appears in Filter 4 - Set field status to "Done"

 

Anyone know if this is possible, or be able to provide an example scripted field script that I can implement?

 

Thanks!

 

Matt

1 answer

1 vote
Nic Brough -Adaptavist-
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.
May 23, 2019

For running JQL in scriptrunner, have a look at https://library.adaptavist.com/entity/perform-a-jql-search-in-scriptrunner-for-jira

However, when you're working with a scripted field on an issue, there's no huge reason to run JQL - it's for searching for issues, and when you already have the issue, you don't need to search for it.  I suspect your scripted field probably should be more simple - a series of "if" statements that return one of your four status values.

Matt May 23, 2019

Thanks - I'll take a look at that link. 

 

A series of statements probably is a better solution, although I'm not an expert at creating scripted fields (yet), so thought using a JQL filter might be more helpful, as I can tweak it more easily if I need to make a change. 

Is there any useful mapping resource that you're aware of for JQL to scrips?  e.g. I would need to learn how to search for something like this "sprint not in futureSprints() or (sprint in futureSprints() and status = done")" in a scripted field?

 

Are there any specific reasons to avoid using JQL in a scripted field? e.g. is it performance heavy? 

Nic Brough -Adaptavist-
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.
May 30, 2019

You can write messy and slow JQL, but there's no reason not to use JQL in a scripted field if you need to.  You can build queries in code by adding clauses together, or just feeding it a valid filter string.

The reason I'm questioning this is that I can't think of a good use for a scripted field that searches for "sprint in futuresprints and status = done" - what do you want that scripted field to do with the list that relates to the current issue?

There are other searches which make more sense - "add up a number field on all the subtasks of this issue", but for ones like that you can get a list of subtasks faster and in less code with the line 

def list-of-issues = issue.getSubTasks()

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira service management, jsm webinar, ai in jsm, opsgenie integration, incident management, virtual agent, atlassian intelligence, ai-powered service desk, it operations, atlassian learning, service management webinar, team '25 recap

What’s new in Jira Service Management 🤔

Discover how Atlassian is revolutionizing service management with cutting-edge solutions for AI-powered support, HR Service Management, or DevOps connectivity.

Register here ⬇️
AUG Leaders

Atlassian Community Events