Forums

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

Run JQL Search and Create Subtasks based on User Picker CF (PostFunction)

Richard Duffy
Contributor
December 15, 2020

HI Everyone

Scriptrunner version - 6.15.0

Jira Version - 8.11.0

Method - Post Function - Custom Script Function

Custom Field - Tempo Validator (User picker single)

JQL Query - project = TEMPO

Goal ->

I want to create a subtask on the issue which triggers the post-funtion based off the JQL query result. 

For example - Lets say the JQL query result has 5 tickets, each of these tickets has a custom field called Tempo Validator which is a single user picker type (Or I can use multi user)

So based on this example the postfunction will create 5 sub-task which will be assigned to the values of the Tempo Validators from the JQL query

 

I have below experimenting with below code but need some help to get this working 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser


def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// The search query
def query = jqlQueryParser.parseQuery("project = TEMPO")

// Results from query
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())

// Get the custom field that you want to update
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName("Tempo Validator")

Collection<ApplicationUser> users= (Collection) issue.getCustomFieldValue(customField);

if(users != null)
{
for(i in 0..users.size()-1)
{
Object AssigneeValue = users.get(i).getKey()
;

issueObject = ComponentAccessor.getIssueFactory().getIssue()
issueObject.setProjectObject(issue.getProjectObject())
issueObject.setIssueTypeId("10003") //id of subtask
issueObject.setParentId(issue.getId())
issueObject.setSummary(issue.getSummary() + ' ' + users.get(i).getDisplayName() + ' - Assessment')
issueObject.setFixVersions(issue.getFixVersions())
issueObject.setAssigneeId(AssigneeValue)
def subTask = issueManager.createIssueObject(ComponentAccessor.jiraAuthenticationContext.getLoggedInUser(), issueObject)
ComponentAccessor.subTaskManager.createSubTaskIssueLink(issue, subTask, ComponentAccessor.jiraAuthenticationContext.getLoggedInUser())
i++
}
}

Thanks in advance

Richard

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
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 Champions.
September 10, 2020

Your requirement is met by the cascading select list, so saying "we don't want to use a cascading select" directly contradicts what you describe.

If you want to do this, use the cascading select list for it.

Is there a reason that you don't want to do this properly?

Venugopal.ReddyL
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 10, 2020

Hi Nic,

Thanks for the response, the thing is we have some limitations with respect to issue page and team doesn't want to use cascading select list.

 

can we control the options behavior using script runner? like below

I have created a issue with approval status value as "Draft" and when i select withdrawn from Draft...it should display error message like Withdrawn should be selected from Requested value option only.

So that user can select requested and then withdrawn.

Thanks

Venu

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 Champions.
September 10, 2020

"Doesn't want to use it" is not a reason, you already said "we don't want to use it".

Why do they not want to use a cascading select?

The cascading select does exactly what you are asking for, and avoids any need to throw up error messages to slow people down.  Don't try to kludge it with other things like Behaviours, you don't need to.  Just use the cascading select.

TAGS
AUG Leaders

Atlassian Community Events