Pre-populate custom field with "current user" value

Hi everyone,

I've been looking everywhere to find a solution for my problem. I have a custom field (user picker) called "responsible" and I need it to be pre-populated with the "reporter" (or current user) value on issue creation. I can't just copy the value as part of a post-function since users should have the possibility to change the value right away (if they are not the person being responsible)

There used to be a plugin addressing the problem which seems to outdated.

https://jira.atlassian.com/browse/JRA-7947?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aworklog-tabpanel

I've been trying to achieve this with the behaviours plugin but with no success.

FormField formAutor = getFieldByID("reporter")
FormField formAG = getFieldByName("Auftraggeber")


if(formAG.getFormValue() == ""){

 formAG.setFormValue(formAutor.getFormValue())
 
}

Any clues or is this a real piece of work? If yes, I have to check with my customer if this request is a must-have...

Thank you,

Christian

5 answers

1 accepted

0 votes
Mizan Community Champion Jul 08, 2012

This should be possible using Behaviours plugin .

Try the below script , even add some logging (you will have to click on enable logging on the behaviours plugin )

FormField formAutor = getFieldByID("reporter")
FormField formAG = getFieldByName("Auftraggeber")
 
 
if(!formAG.getFormValue()){
 
 formAG.setFormValue(formAutor.getFormValue())
  
}

Do I have to active another logging behaviour (set a logger to debug?)

Mizan Community Champion Jul 08, 2012

yes there is a enable logging link on the behaviours page

I know, just wanted to check if I had to set a JIRA logger to "debug" instead of warning in order to see the entries in the log file.

Mizan Community Champion Jul 08, 2012

Ok , so is the script working ?

Hey, it's not working. Can't view the log right now since the server admin has already gone home:-) I even tried without the if clause with no result. The value doesn't get copied.

Any chance of retrieving the current reporter (or current user) without using the field "reporter" on my issue create screen? My customer doesn't want the creator field being displayed...

Mizan Community Champion Jul 09, 2012

yes you can use the following line

User currentUser = componentManager.getJiraAuthenticationContext().getUser()

I've achieved it by using:

import com.atlassian.jira.ComponentManager

FormField formAG = getFieldByName("Auftraggeber")       

currUser = ComponentManager.getInstance().getJiraAuthenticationContext().getUser()
currUserName = currUser.getName()

if(!formAG.getFormValue()){     
 
 formAG.setFormValue(currUserName) 
 }

Mizan Community Champion Jul 10, 2012

Great :)

Hey can you try the below code .. it wont make much difference

import com.atlassian.jira.ComponentManager
 
FormField formAG = getFieldByName("Auftraggeber")      
 

 
if(!formAG.getFormValue()){    
formAG.setFormValue(ComponentManager.getInstance().getJiraAuthenticationContext().getUser().getName())
 }

Got a typo:

FormField formAutor = getFieldById("reporter")
FormField formAG = getFieldByName("Auftraggeber")
if(!formAG.getFormValue()){
formAG.setFormValue(formAutor.getFormValue())
}

I had ID :-)

The script worked for me also in the Behaviours plugin. In addition, I would like to choose a different user in the custom field (user picker) if it is not the Reporter. Is there a simple "else" statement I could use?

Hi,

I have almost similar issue. Could someone please help me.

My issue is, I have a custom field and a system field (Reporter). I would have a value in my custom field and I want that value to auto populate to the Reporter field if that user(value) listed in custom field maches to the user list in Reporter field.

How do I do this?

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,936 views 12 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot