Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to set default username to the user picker cf?

Teja December 21, 2016

Hi,

Can I able to set default user name to the user picker custom field on the Create screen same like 'Reporter' field,

but not the currentUser some default name like 'Johnson' to 'Validating User'.

image2016-12-22 11:46:24.png

Thanks 

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Jonny Carter
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.
December 23, 2016

To add on to Kristian's answer, it is possible to set the default value for a custom user picker field using Behaviours as well.

The main benefit of using a behaviour instead of a post-function on the create transition is that the end user will be able to see and make an informed change to the user picker field. Doing the script on the post-function can be a little opaque; the user leaves validating user blank, and only sees it populated after they submit the new issue.

If the user you want to set it to is always the same one, you could simply put their username in the setFormValue method of an initialiser function:

def validatingUser = getFieldByName("Validating User")
validatingUser.setFormValue("johnson")

If it needs to be more dynamic, you could use classes like the UserService and UserSearchService to find the appropriate user and get their username.

Teja December 25, 2016

It worked...

Thank you so much Jonny.

Teja December 25, 2016

Hi Jonny,

I cannot able to change default username like johnson, its populating default one when tired to change it.

It would be like user can change Validating User field or if not leave it as default Johnson. 

0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 22, 2016

Hi Teju,

This requirement does not need script runner and can be completed by installing the JIRA Suite Utilities plugin and using a Copy Custom Field Post function that is placed as the last post function on the create transition. 

The post function would be configured similar to the screenshot below and would copy the value from the Reporter  field to the Validating User field.

Screen Shot 2016-12-22 at 12.11.42.png

Unfortunately you could not set a user picker field to have a value which is not a user object. If you want to set it to a name such as a users full name then you would need to use a script similar to below which would set a single line text field.

// Required Import Statements
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue


// Get a pointer to the issue
MutableIssue issue = issue

// Get the current Issue
MutableIssue SubjectIssue = issue

// Get a pointer to the Custom Field Manager
def customFieldManager = ComponentAccessor.getCustomFieldManager()

// Get the value of the Full Name Scripted Field
def validateUserCN = SubjectIssue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Validating User Common Name"))

// Get the reporter value
def reporter = SubjectIssue.getReporter().name.toString()

// Check if the reporter field contains a value
if(reporter !=null){
    // Set the Validating user field with the value of the reporter field
    SubjectIssue.setCustomFieldValue(validateUserCN, reporter);
}

 

I hope this helps.

Thanks

Kristian

Teja December 25, 2016

Thanks for your support Kristian.

TAGS
AUG Leaders

Atlassian Community Events