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
Accepted answer

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
Posted Thursday in Jira

Continuous visibility with the new Jira Software Cloud and Bitbucket Cloud integration

Hey Atlassian community, I am a PM on the Bitbucket Cloud team and I am excited to share that we just released an improvement to the Jira Software and Bitbucket Cloud integration. With the newly im...

81 views 0 4
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