It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

6 answers

1 accepted

0 votes
Answer accepted

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?)

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.

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...

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) 
 }

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?

Hello,

can someone advise me where to get Behaviours plugin, please? I have looked up on Atlassian marketplace but with no success. Nothing like Behaviours plugin for Jira.

Thank you in advance,

L.

It's part of the ScriptRunner plugin

Thank you, it helped.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Managing Incidents - The roof is on FIRE!

The roof is on FIRE… network outages, broken processes, upset clients and employees. Each day seemed to bring more and more issues. Incidents were communicated via email, messengers (skype or teams) ...

135 views 0 1
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you