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.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.