Hey,
I need to copy value form last comment to my custom field (Simple multiline text field).
Below is my code, but it doesn't work. Part about last comment is okay. I think that setting value is wrong, any ideas why? I can't see any errors...
import com.atlassian.jira.component.ComponentAccessor
String lastcomment = ""
def comments = ComponentAccessor.commentManager.getComments(issue)
if (comments) {
lastcomment = comments.last().body
}
def changeCf = customFieldManager.getCustomFieldObjectByName("MyCustolField1")
issue.setCustomFieldValue(changeCf, lastcomment)
Hi Rafal!
If this is a postfunction, you need to save your change!
Let's say that I want to change the assignee of an issue in a postfunction.
I would use something like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def issueManager = ComponentAccessor.getIssueManager()
MutableIssue issue = issueManager.getIssueByCurrentKey("JRA-1")
def userManager = ComponentAccessor.getUserManager()
def anuser = userManager.getUserByKey("anuser")
//A single user selected
issue.setAssignee(anuser)
//Update your issue, if you don't do this, you might not see the change.
issueManager.updateIssue(anuser, issue, EventDispatchOption.ISSUE_UPDATED, false)
Do say if this didn't help, or if I can help you further.
Cheers!
DY
Hey, that helps.
This is my final code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def updateCustomFieldValue(issue, String fieldName, String newValue, user) {
def customField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName(fieldName)
issue.setCustomFieldValue(customField, newValue)
ComponentAccessor.issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)}
def getUserByName(userName) {
ComponentAccessor.userManager.getUserByName(userName)}
def user = getUserByName("tech")
String lastcomment = ""
def comments = ComponentAccessor.commentManager.getComments(issue)
if (comments) {
lastcomment = comments.last().body
}
updateCustomFieldValue(issue, "My field1", lastcomment, user)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.