Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Behaviours Prepopulate currentUser into user picker on Create screen

Tomáš Vrabec
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.
July 30, 2019

Hi Community,

looking for the solution for one of my clients.

They would like to have a Custom user user picker called "Requestor" have prepopulated with currentUser when they open the Create screen.

We got Behaviors available, but I am not able to make it work.

Can you hint me guys pls?

Cheers, Tom

1 answer

1 accepted

0 votes
Answer accepted
JiraJared
Community Champion
August 1, 2019

Something like...

import com.atlassian.jira.component.ComponentAccessor

if (getActionName() == "Create Issue") {
// Get the current user
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// Get the Requestor field
def requestor = getFieldByName("Requestor")
requestor.setFormValue(currentUser.key)
}

** not tested, wrote from memory.

Or maybe just set the field the same as reporter (assuming they can't change the field on Create) 

Tomáš Vrabec
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.
August 1, 2019

They can do change on the create.

The point behind this is to not disturb user by filling this, if they are requesting on their own behalf, but give them option to change that, if they are requesting on behalf of someone else.

Will try this one, not skilled with this level of scripting at all.

Like JiraJared likes this
Tomáš Vrabec
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.
August 1, 2019

@JiraJared solved with slightly modified code

import com.atlassian.jira.component.ComponentAccessor
// Get the current user
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// Get the Requestor field
def requestor = getFieldById("customfield_10301")
if (requestor.formValue == "") {
requestor.setFormValue(currentUser.key)
}
Like JiraJared likes this

Suggest an answer

Log in or Sign up to answer