Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,158
Community Members
 
Community Events
176
Community Groups

How to use script runner to parse a wiki style table in a multi-text field

Edited

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.Screen Shot 2022-05-04 at 10.46.54 PM.png

1 answer

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.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}

@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.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events