JQL search with a different user when scripting: Scriptrunner

I am trying to change the user when doing a JQL search for a scripted field. I realizd that the current user will not be able to browse the project so I would need to use a user that is able to browse the project. A piece of my script can be seen below.  I would like to change the def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() to a different user. As an example, maybe the user name can be JohnDoe


def user = ComponentAccessor.getJiraAuthenicationContext().getUserByName("JohnDoe")

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.web.bean.PagerFilter;
import java.lang.Object
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import static java.lang.Math.*
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.acme.CreateSubtask")

boolean check =true

String jqlVaca = 'project = HR AND issuetype = "Employee Information"';
log.debug("Get filter string")

// Get a search-Object for JIRA
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issuesInfo
SearchService.ParseResult parseResultVaca =  searchService.parseQuery(user, jqlVaca)

if (parseResultVaca.isValid()) {
   	 issuesInfo = (searchService.search(user, parseResultVaca.getQuery(), PagerFilter.getUnlimitedFilter()).getIssues())
log.debug("Parse is Valid")
	check =1;


1 answer



It has the function "setLoggedInUser(ApplicationUser user)". 
This is used in places like Jelly where we need to switch the identity of a user during execution.

To get the user i think you need UserManager and the getUserByName (or Key) function.

 I never used it but this should be the function you need.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

457 views 8 27
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you