The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with Inserting Table into Custom Field via Post-Function ScriptRunner

Dexia O'Shea
Contributor
March 24, 2025

I'm trying to insert a table into a custom field value , collection of requirements, when an issue is transitioned and i'm adding it as a post function with script runner. this is my code but it is not working, the last line is returning with a red underline

 

// define custom field
def customFieldId = "customfield_10281"

// Define the content for the custom field
def requirementsContent = """
<strong>Collection of Requirements</strong>
<table>
<tr>
<th>Requirement</th>
<th>Description</th>
</tr>
<tr>
<td>Requirement 1</td>
<td>Description for Requirement 1</td>
</tr>
<!-- Add more rows as needed -->
</table>
"""

// Set the custom field value
issue.setCustomFieldValue(customFieldId, requirementsContent)

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Pasam Venkateshwarrao
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
March 28, 2025

Hi @Dexia O'Shea 

Welcome to the community,Ensure your custom field is a text field or a field that supports rich text formatting, as this will allow you to display the table correctly

// Get the issue
def issue = getIssue()

// Get the custom field ID (replace with your field ID)
def customFieldId = 'your_custom_field_id'

// Get the custom field object
def customField = getFieldById(customFieldId)

// Define the table content (using Markdown or HTML)
def table = """
| Header 1 | Header 2 | Header 3 |
|---|---|---|
| Row 1, Cell 1 | Row 1, Cell 2 | Row 1, Cell 3 |
| Row 2, Cell 1 | Row 2, Cell 2 | Row 2, Cell 3 |
"""

// Set the value of the custom field
customField.setFormValue(table)

 

In The script:

setFormValue(table)Sets the value of the custom field to the provided table content

HTML Code:

 

// Get the issue
def issue = getIssue()

// Get the custom field ID (replace with your field ID)
def customFieldId = 'your_custom_field_id'

// Get the custom field object
def customField = getFieldById(customFieldId)

// Define the table content (using HTML)
def table = """
<table border="1">
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
<td>Row 1, Cell 3</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
<td>Row 2, Cell 3</td>
</tr>
</table>
"""

// Set the value of the custom field
customField.setFormValue(table)

 

Hope this helps

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events