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

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events