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.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.user.ApplicationUser
def issue = event.issue
def cfUsersInLastComment = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("Users in last comment").first()
def comments = ComponentAccessor.commentManager.getComments(issue)
String strComment = comments.last().body
List<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)
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sal ,
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Andrea Pannitti,
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.
BR,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sal ,
I think your problem depends on the fact that from the comment are extracts all users and therefore you have a list of users.
If so, try changing the last line of the previous code as follows:
cfUsersInLastComment.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cfUsersInLastComment), users.first()), new DefaultIssueChangeHolder())
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.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sal,
this issue can be solved by ScriptRunner. Have you ScriptRunner?
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.
Ok @Sal ,
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.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.user.ApplicationUser
def issue = event.issue
def cfUsersInLastComment = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("Users in last comment").first()
def comments = ComponentAccessor.commentManager.getComments(issue)
String strComment = comments.last().body
List<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)
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.
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.