We have Jira Cloud. I am using in-browser script console.
I have a script that runs with expected outcome as long as the issue key is hardcoded; which of course defeats the purpose.
I have a Script Listener in place that triggers the script when a new comment is added.
All I want is the issue key of the of the work item on which this script will be triggered.
I have used "issue.key", "issue.id" and I get the same error
Error: java.lang.RuntimeException: groovy.lang.MissingPropertyException: No such property: id for class: com.adaptavist.hapi.cloud.jira.issues.Issues at Script_7434c7615767409bab7286815949fe66.run(Script_7434c7615767409bab7286815949fe66.groovy:5) at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:35) at com.adaptavist.sr.cloud.workflow.AbstractScript.runScriptFromRequest(AbstractScript.groovy:98) at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:61) at WebhookExecution1_groovyProxy.run(Unknown Source)
I just need the issue key to be stored in a variable, in this case def issueKey
Thanks!
Screenshots below:
Hi @IT Brute
From the screenshot you have provided, it doesn't appear that you are using the issue key property. Instead, you are using ScriptRunner's HAPI's Issues.issueIdOrKeys.
This will not work because when using Issues.issueIdOrKeys, you are taking a list of issue ids or keys.
Instead, to get the issue, you need to do something like:
def eventIssue = Issues.getByKey(issue.key as String)
Let me know how it goes.
Thank you and Kind regards,
Ram
Hey @Ram Kumar Aravindakshan _Adaptavist_ thanks for your reply
Issues.getByKey(issue.key as String) doesn't work either. It gives the following error:
Error: java.lang.RuntimeException: org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: static com.adaptavist.hapi.cloud.jira.issues.Issues.getByKey() is applicable for argument types: (com.adaptavist.hapi.cloud.jira.issues.IssueImpl) values: [NCRVER3-494] Possible solutions: getByKey(java.lang.String) at WebhookExecution1_groovyProxy.run(Unknown Source) Caused by: groovy.lang.MissingMethodException: No signature of method: static com.adaptavist.hapi.cloud.jira.issues.Issues.getByKey() is applicable for argument types: (com.adaptavist.hapi.cloud.jira.issues.IssueImpl) values: [NCRVER3-494] Possible solutions: getByKey(java.lang.String) at Script_8b638b0c09eb84d26a6943c47e6d6acf.run(Script_8b638b0c09eb84d26a6943c47e6d6acf.groovy:6)
My script:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @IT Brute
Why are you using the Issues.getByKey(issueKey) function 2 times, i.e.
def issueKey = Issues.getByKey(issue.key as String)
def commentList = Issues.getByKey(issueKey).fields.comment.comments.body[0]
You only need to invoke the issue object once via Issues.getByKey as shown below:-
def eventIssue = Issues.getByKey(issue.key as String)
Once the issue object is obtains, you can directly invoke the comment list and the content of the comment list as shown below:-
def commentList = eventIssue.comments // list of comments
// to ge the last comment body
if (comments.size()) {
def lastComment = comments.last()
def commentBody = lastComment['body'].toString()
// your code
}
Below is a fully working code for your reference:-
def eventIssue = Issues.getByKey(issue.key as String)
def comments = eventIssue.comments
if (comments.size()) {
def lastComment = comments.last()
def commentBody = lastComment['body'].toString()
eventIssue.update {
setCustomFieldValue('Sample Text', commentBody)
}
}
The sample code above does the following: when a comment is added to an issue, the comment body is copied to a text field. The text field will only be updated with the latest comment body.
Below is a screenshot of a working Listener configuration for your reference:-
Please make the suggested modifications and retest it in your environment.
I'm looking forward to your feedback.
Thank you and Kind regards,
Ram
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.