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
maybe
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") log.setLevel(Level.DEBUG) 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") } else check =1;
JiraAuthenticationContext 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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.