Hello Everyone,
I would like to create Project automation where we can copy the username when a comment is added to a user picker field.
Any idea how this can be done?
BR,
Hi @Sal ,
I copied my reply in this separated answer; so, if it's ok for you, you can accept this. Thank you.
let be "Users in last comment" the user picker (multi-user) that we want fill with users in last comment.Then add a new custom Script Listener that starts on "Issue Commented" event and set in Script this code:
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.ModifiedValueimport com.atlassian.jira.issue.util.DefaultIssueChangeHolderimport com.atlassian.jira.user.ApplicationUserdef issue = event.issuedef cfUsersInLastComment = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("Users in last comment").first()def comments = ComponentAccessor.commentManager.getComments(issue)String strComment = comments.last().bodyList<String> userNames = strComment.findAll("\\[~.*?\\]")def users = new ArrayList<ApplicationUser>()userNames.each {users.add(ComponentAccessor.userManager.getUserByName(it.substring(2, it.length()-1)))}cfUsersInLastComment.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cfUsersInLastComment), users), new DefaultIssueChangeHolder())
So, when a new comment is added to the issue, users in comment will be added to the user picker field.
Note: Each User in comments must be written as: @username (by selecting the one you want)
@Sal Are you coping the username from the individual who created the comment? If so you would need to get the comment author using the following smart value {{comment.author.displayName}} This could then be added to a custom field. I am not sure if you will be able to set a user picker field with it. You would have to try.
@Brant Schroeder Sorry, I was not clear. When a user comments on a ticket with something like "add username" then the username should be added to a user picker custom field and delete the comment.
Hi @Sal,
this issue can be solved by ScriptRunner. Have you ScriptRunner?
@Andrea Pannitti I have script runner and automation for jira as well.
Hello @Andrea Pannitti,
Sorry, I was away for a few days. This is working as you said. But my scenario is a little different.
It is like I have a single select field and it should only populate when there is some specific word in a comment such as "additional" then "username". It will pick the username from the comment to the single select field and delete the comment.
I am new to groovy and not sure about the changes that can be done here.
Thanks in advance!
I'll answer you by points:
Thus, it seems that the proposed solution lacks only the deletion of the comment.If not, what is wrong for you?I would ask you to be as precise as possible in order to clarify what you need.
Thanks
When using a multi-user picker field it's working fine but I am not able to use this script for a single user picker field.
It looks like you're new here. Sign in or register to get started.