It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Adding Request participants through Scriptrunner

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

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.

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
Community showcase
Published in Jira Service Desk

The Complete Guide to Atlassian for ITSM

Hi Atlassian Community! This is Teresa from the Atlassian team. My colleague Paul Buffington @Buff and I are excited to share a brand new ITSM resource we’ve created – "The Complete Guide to At...

579 views 7 12
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you