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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.