Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Adding Request participants through Scriptrunner

Andrea Caprioli May 22, 2018

Hi,

I'm trying to automate some parts of our service desk. One task is automatically adding the project lead as request participant whenever an user requests access to a project as an administrator, and so far, I've got this code snippet (this is the 'search user and add as participant' part):

void addLead() {
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class);
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class);
def query = jqlQueryParser.parseQuery('project="'+(issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("JIRA Project")) as String)+'"');
def results = searchProvider.search(query, issue.assignee, PagerFilter.getUnlimitedFilter());
results.getIssues().each {documentIssue ->
issue.setCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10101"),documentIssue.getProjectObject().getProjectLead() as ArrayList<ApplicationUser>);
return;
}
}

 While it does not fail in any way, the change is not saved to the issue - script execution is marked as successful but no participant is added. The script is ran as a post-function set before storing&reindexing, so I don't think I need to call updateIssue(), but I'm not certain.

I'm afraid that either the change is not saved or the project is returned, but the query should be working correctly.

1 answer

0 votes
Alexey Matveev
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 22, 2018

You need the updateIssue statement because the issues, which you change, are not the current issue. You take these issues from your JQL query. storing&indexing works for the current issue only.

Andrea Caprioli May 22, 2018

But I am trying to change the current issue (the Service Desk one, maybe I wasn't too clear, sorry).

 

Getting issues through the JQL was the fastest option I thought of to get the ProjectObject I needed to obtain the correct project's lead - and that's all I use them for.

Alexey Matveev
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 22, 2018

Make sure that you enter the each loop and you choose the right value. You can add log statements to your code and see the output in the atlassian-jira.log file

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events