Hi,
I have to update issue's change history using java api. I succeeded to retrieve the ChangeItemBean via changeHistoryManager.getChangeItemsForField
However when setting the new value using setToString(), the update is not populated in the history.
Any idea?
Thanks
I don't know if it's possible to change the history.
You can definitely read the history.
There is a method to clear the history.
And you can add to the history using the ChangeLogUtils.
But there is no updateChangeItem method to store/persist the ChangeItemBean that you've attempted to modify.
At best, you can retrieve a changeItem Bean, modify it, then store it as a new ChangeGroup/ChangeItem. But the old one will still be there.
Hi Peter,
Thanks for you reply
The goal behind history update is migrating duplicated storypoint to the default one.
Any idea how to achieve that kind of migration?
Regards,
Ahmed
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, I don't know what you mean. Can you give more details?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter,
The goal is to update the following history item by replacing story points obsolete 1, by story point (default one)
Thanks
Ahmed
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The only way to change this I think would be through making changes directly in the database and that's never recommended.
But presumably, this means that you had a customfield called story points that you renamed "story points_obsolete" but you now also have the default "story points" field created by jira software. After the new field was created, all your issues would have had to be converted from the old to the new field. The entry (New story points going from null to 7 should be listed). I am not sure what you think changing the field label in the history will do, but wouldn't it be best to show the entire actual history?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter,
From your point of view, what will be the best approach to copy all items history from from old to new field?
Thanks
Ahmed
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
History item are associated with an issue object, not a custom field. The "fieldname" is just an attribute of a change item and has no direct link to that field.
My recommendation is to no copy the history. The only thing I would be comfortable recommended with regards to the issue history is to insert a single history change item that would document the change in the field name.
Something like
Field | Old Value | New Value
Field Replaced | story points_obsolete | Story Points
This would allow a user to to follow the chronology of events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Peter.
So how would one append to issue's history? I haven't found any method in java doc yet.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You'll want to use the ChangeLogUtils for that
Here is a couple of sample functions that uses that:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeLogUtils
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.IssueEventBundleFactory
import com.atlassian.jira.user.ApplicationUser
import org.ofbiz.core.entity.GenericValue
def createChangeLog(Issue issue, String fieldName,String oldValue,String newValue,ApplicationUser currentUser,String eventName,String commentBody="",Map params = [:]) {
def changeHolder = new DefaultIssueChangeHolder();
def changeItemBean = new ChangeItemBean(ChangeItemBean.CUSTOM_FIELD, fieldName, "", oldValue, "", newValue)
changeHolder.addChangeItem(changeItemBean);
def changeGroup = ChangeLogUtils.createChangeGroup(currentUser, issue, issue, changeHolder.getChangeItems(), false);
if(eventName){
dispatchEvent(issue, currentUser, eventName, changeGroup, commentBody, params)
}
}
def dispatchEvent(Issue issue,ApplicationUser currentUser,String eventName, GenericValue changegroup,String commentBody = "",Map params = [:]) {
def eventFactory = ComponentAccessor.getComponent(IssueEventBundleFactory.class)
def eventId = ComponentAccessor.eventTypeManager.eventTypes.find { it.name == eventName }?.id
if(eventId){
log.debug "Dispatching event $eventName ($eventId)"
def comment
if(commentBody) {
comment = ComponentAccessor.commentManager.create(issue, currentUser, commentBody, false)
}
def eventBundle = eventFactory.wrapInBundle(new IssueEvent(issue, currentUser, comment, null, changegroup, params, eventId, true))
//issueEventManager.dispatchEvent(eventBundle)
ComponentAccessor.issueEventManager.dispatchEvent(eventId,issue, currentUser, comment,null, changegroup,params, true)
} else {
log.warn "No event found matching name: $eventName"
}
}
def issue = ComponentAccessor.issueManager.getIssueObject('JSP-1922')
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
createChangeLog(issue, "dummy field", "old dummy value", "new dummy value", currentUser, 'Issue Updated')
This will produce a history item that looks like this:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Peter,
I am beginner in JIRA. So I wanted to know if there is any stable platform to connect from Java to JIRA without using REST API? Can I use native Java libraries or any other additional libraries to connect to JIRA?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The normal way to connect to Jira from Java is to create a plugin using the atlassian SDK.
If you want to connect to a Jira instance from outside of Jira then REST API is the only way.
There is a Java wrapper for the REST API, but I've never used it and I'm not a fan.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is it possible to create changegroup using changeLogUtils with a specified timestamp? I can create the changeItemBean with timestamp. Unfortunately, when I create a changeGroup using the list of changeItemBean created, it make me a changegroup to now, but not the timestamp in changeItemBean
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't know. I never tried.
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.