Hello,
I'm trying to set up a script in script runner that would trigger when a ticket transitioned to completed, this script would then take rows in the wiki-style table in a multi-text field and create a ticket in another project for each of said rows.
would probably be something close to https://community.atlassian.com/t5/Adaptavist-questions/ScriptRunner-Read-Description-Field/qaq-p/1930159
This is what the table would look like.
Hi - this can actually be done with Automation.
Turns out my answer had broken images, so I've just written a new one here:
If somebody wants to actually do this with Groovy and Scriptrunner, you should feel free to submit an answer.
I would like to run this with Groovy and scriptrunner. Can you provide me the code snippet for the same?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
using groovy/scriptrunner is not that complicated. Maybe the following examples of writing users from a multi user field into a table, helps you:
{code:java}
package de.metamorphant.jira.scripts.Examples
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.user.ApplicationUser
CustomFieldManager customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
IssueManager issueManager = ComponentAccessor.getComponent(IssueManager)
JiraAuthenticationContext jiraAuthenticationContext = ComponentAccessor.getComponent(JiraAuthenticationContext)
ApplicationUser currentUser = jiraAuthenticationContext.getLoggedInUser()
CustomField usersField = customFieldManager.getCustomFieldObject("customfield_12345")
List<ApplicationUser> userList = issue.getCustomFieldValue(usersField) as List<ApplicationUser>
StringBuilder stringBuilder = new StringBuilder()
//Adding the Header
stringBuilder.append("||Username||User displayname||Email||Active||")
//iterating through the user list and adding the rows to the table
userList.each {
stringBuilder.append("\n|${it.username}|${it.displayName}|${it.emailAddress}|${it.isActive().toString()}")
}
//set table in multiline textField of mutable issue
CustomField textField = customFieldManager.getCustomFieldObject("customfield_23456")
MutableIssue mutableIssue = issue as MutableIssue
mutableIssue.setCustomFieldValue(textField, stringBuilder.toString())
//Write to database
issueManager.updateIssue(currentUser, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
{code}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bastian Wedler Could I know whether any interface that help to convert renderedBody content into customfield value?
There are so many kinds of wiki style editor provided.
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.