I'm looking for the best way to grab all populated fields for an issue (both system and custom) in a groovy post-function (which will then be passed on to some other scripts for some automated tasks). Below is a way I was able to do it, but I fear that I am using non-standard or deprecated means to go about it. Can someone take a look, and let me know if it looks good?
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
IssueManager issueManager = ComponentManager.getInstance().getIssueManager()
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
myissue = issue.key
Issue issue = issueManager.getIssueObject( "$myissue" )
def cflist = customFieldManager.getCustomFieldObjects(issue)
def map = new HashMap<String,String>()
cflist.each {cf ->
Object value = issue.getCustomFieldValue(cf)
if(value){
map << [(cf):"$value"]
}
}
def systemfields = issueManager.getIssue("$issue") //using GenericObject since it seems to contain issue fields -- appreciate alternative suggestions
def iterator = systemfields.entrySet().iterator()
while (iterator.hasNext()) {
if (! iterator.next().value) {
iterator.remove()
}
}
map << systemfields
def body = map.collect { k, v -> "${k}^^${v}" }.join('::')