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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.