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

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

Setting custom field value in jira

Hi, 

I am trying to set a custom field value in Jira with the current logged in user details( Name) . However the script is not giving an error, but also not displaying an output.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueImpl
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.util.ErrorCollection;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.user.ApplicationUser;

MutableIssue missue = issue
ComponentManager componentManager=ComponentManager.getInstance();
ApplicationUser appUser = componentManager.getJiraAuthenticationContext().getUser()
User user = appUser.getDirectoryUser();
String currUserFullName = user.getDisplayName();
log.error(" Value: $currUserFullName ---")
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def myCustomField = customFieldManager.getCustomFieldObjectByName("Custom field name")
String producttype = currUserFullName
if(myCustomField)
{
log.error("Entering If")
//String producttype = (String) issue.getCustomFieldValue(myCustomField)
missue.setCustomFieldValue(myCustomField,producttype)
}
//log.error("COO Value: $producttype ---")

 

 

"Custom field name" initial value is null, my purpose is to use this script to set the value of this field to the logged in username.

 

please assist

1 answer

Hello @Hemanshu Sood

There are several errors in script, try script bellow

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.user.ApplicationUser;

MutableIssue missue = issue
ApplicationUser appUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
String currUserFullName = appUser.getDisplayName();
log.error(" Value: $currUserFullName ---")
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def myCustomField = customFieldManager.getCustomFieldObjectByName("Custom field name")
String producttype = currUserFullName
if(myCustomField)
{
log.error("Entering If")
//String producttype = (String) issue.getCustomFieldValue(myCustomField)
missue.setCustomFieldValue(myCustomField,producttype)
}
//log.error("COO Value: $producttype ---")

And what is your jira version?

Still not working @Mark Markov, no error in logs though.

Jira version is 6.4.13

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,881 views 11 5
Join discussion

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