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?
Hi @Vimalraj Periyasamy
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.ComponentAccessorimport com.atlassian.jira.event.type.EventDispatchOptionimport com.atlassian.jira.issue.CustomFieldManagerimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.IssueManagerimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.fields.CustomFieldimport com.atlassian.jira.security.JiraAuthenticationContextimport 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 HeaderstringBuilder.append("||Username||User displayname||Email||Active||")
//iterating through the user list and adding the rows to the tableuserList.each {stringBuilder.append("\n|${it.username}|${it.displayName}|${it.emailAddress}|${it.isActive().toString()}")}
//set table in multiline textField of mutable issueCustomField textField = customFieldManager.getCustomFieldObject("customfield_23456")MutableIssue mutableIssue = issue as MutableIssuemutableIssue.setCustomFieldValue(textField, stringBuilder.toString())
//Write to databaseissueManager.updateIssue(currentUser, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
{code}
@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.
It looks like you're new here. Sign in or register to get started.