hello,
I have a groovy script that copies the values of custom fields into a comment.
But the whole is very static. (including the names of the custom fields)
it should now be adjusted so that it only copies the custom fields, which also have a value.
See the current script below. (I know it's not perfect, sorry, guys!)
use case info: it is a service desk project where bugs are reported. then the issues moved by an owner into a normal jira project of the corresponding team. Therefore the values of the custom fields should be copied into a comment (because the custom fields are not in the normal projects)
// Required Imports
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.CustomFieldManager;
// Get a pointer to the current logged in user
def CurrentUser = ComponentAccessor.getJiraAuthenticationContext().getUser().name
// Get the current Issue
Issue issue = issue
// Get the Manager classes required
def CommentManager commentManager = ComponentAccessor.getCommentManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// List of Custom Fields for Comment the CommentText as the value of my text field
String CommentText1 = "Name of custom_field1: " + customFieldManager.getCustomFieldObject("customfield_123").getValue(issue).toString() + "\n\n"
String CommentText2 = "Name of custom_field2: " + customFieldManager.getCustomFieldObject("customfield_124").getValue(issue).toString() + "\n\n"
String CommentText3 = "Name of custom_field3: " + customFieldManager.getCustomFieldObject("customfield_125").getValue(issue).toString() + "\n\n"
String CommentText4 = "Name of custom_field4: " + customFieldManager.getCustomFieldObject("customfield_126").getValue(issue).toString() + "\n\n"
String CommentText5 = "Name of custom_field5: " + customFieldManager.getCustomFieldObject("customfield_127").getValue(issue).toString() + "\n\n"
//Create Comment with all informations
CommentTextSummary = CommentText1 + CommentText2 + CommentText3 + CommentText4 + CommentText5
commentManager.create(issue,CurrentUser,CommentTextSummary,true)
I minimized the script to five custom fields.
Can someone help me?
Thank you for your answers and help! 