hello everybody,
i want to generate a comment over script runner and a groovy script when executing a transition.
that is the script. i want to read the value in the reporter-field
import com.atlassian.jira.issue.comments.CommentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.user.*; import com.atlassian.jira.issue.fields.DefaultFieldManager; ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser(); CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() reporter = ""+issue.getFieldValue( ComponentAccessor.getFieldManager().getFieldObjectByName("Reporter")).displayName wertreporter = issue.getFieldValue(reporter) reporter = "Hallo *" + wertreporter + "*, \ \n\ndein Notebook wird vorbereitet.\ \n\nGrüsse\ \nTechnical Services" CommentManager commentMgr = ComponentAccessor.getCommentManager() commentMgr = (CommentManager) ComponentAccessor.getComponentOfType(CommentManager.class) //Der wirkliche Kommentar commentMgr.create(issue, currentUser, reporter, true)
this is the error:
Time (on server): Wed May 24 2017 13:13:53 GMT+0200 (W. Europe Daylight Time) The following log information was produced by this execution. Use statements like:log.info("...") to record logging information. 2017-05-24 13:13:53,894 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2017-05-24 13:13:53,894 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: ITSD-161, actionId: 61, file: /data/jira/home/groovy/ts-jsd-notebook-change-deployment.groovy groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.fields.DefaultFieldManager.getFieldObjectByName() is applicable for argument types: (java.lang.String) values: [Reporter] at ts-jsd-notebook-change-deployment.run(ts-jsd-notebook-change-deployment.groovy:14)
can somebody help?
toni
Hey Toni,
I've taken your script and cleaned it up a little bit for you. I tested it myself and didn't get any kind of error:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.comments.CommentManager import com.atlassian.jira.user.ApplicationUser import com.onresolve.jira.groovy.user.FieldBehaviours ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser def wertreporter = issue.reporter.name def reporter = "Hallo *" + wertreporter + "*, \n dein Notebook wird vorbereitet.\n Grüsse \n Technical Services" CommentManager commentMgr = ComponentAccessor.getCommentManager() //Der wirkliche Kommentar commentMgr.create(issue, currentUser, reporter, true)
I think this should do what you are wanting. Here are some detailed steps over how to use this script in a post function:
Steps to use in transition:
You may then publish the workflow and you're good to go.
Hello Aidan,
i know how to edit and publish a workflow :->
My Problem was that i want to print the displayname of the reporter over the grrovy script.
Anyway thank you it works fine.
Best regrads
Roni
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Aidan,
how can i print the displayname and not the username?
Hallo test,
dein Notebook wird vorbereitet.
Grüss
Technical Services
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.
Can you please help me how to print a custom message with approver or rejector name. For ex: if the issue is in waiting for approval, once it is approved i would like to display a comment as "approved by name of the approver "
Any help will be greatly appreciated as it is very urgent.
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.
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.
@[deleted] It depends on how your approval process works, but assuming that the issue will be approved when the approver transitions the issue, you can set up a Script Post-Function that contains code to create a comment like this:
import com.atlassian.jira.component.ComponentAccessor
def commentManager = ComponentAccessor.commentManager
commentManager.create(issue, currentUser, "This is a new comment by ${currentUser.name}", false)
Both the variables "issue" and currentUser will be available to you when creating a Custom Script Post-Function.
Let me know if that'll work for you! :D
Aidan
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.