How do I create a table in description section using rest API in javascript ?

Rahim T_S
Contributor
January 30, 2023

I'm using https://www.npmjs.com/package/jira-client wrapper class to create a Jira automation utility and one of the requirements is to read data from excel sheet and upload the relevant data as a table to the description section of the created issue

This wrapper class seems to allow only string type as acceptable value. I was able to parse a simple html table as a string and create a table but when it comes to big tables how can I handle those ?

Can I use the custom fields option to do this ?

From the API documentation it seems that the description field can be modified to send tables, can someone help me figure out how ?


Thanks

2 answers

1 accepted

3 votes
Answer accepted
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2023

Hi @Rahim T_S ,

tables in description is part of the text. You could try to add the following :

||Heading||

|Your cell value|

Please let me know if it works,

Fabio

Rahim T_S
Contributor
January 31, 2023

Hi @Fabio Racobaldo _Herzum_ that seems to work. Thank you

I added as 

description: "|Name||Rahim|" and I got the result reflected in the issue.
But how can I create rows and columns ?

I tried like 
description: "||Name||||Title|||Rahim||Software Engineer|"

but got all as values of a row
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2023

| column 1 | column 2 |

in order to create a new row you just need to add carriage return in your text.

Like Rahim T_S likes this
Rahim T_S
Contributor
January 31, 2023

@Fabio Racobaldo _Herzum_ That worked. Thank you so much for your help

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2023

you're welcome @Rahim T_S  ;)

Like Rahim T_S likes this
akshatjain057
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 20, 2023

does it actually renders as the table ? it comes as text only for me , how to add carriage return in text on mac ?

Tyler Do March 22, 2023

@Fabio Racobaldo _Herzum_ 

I tried 
description: `||Test1|| |Test2|`

But i just get exactly text in my description, there's no actual table in my ticket, can you help, appreciate

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 23, 2023

 @Tyler Do , please check the renderer associated to description field in the field configuration

Tyler Do March 23, 2023

@Fabio Racobaldo _Herzum_  I don't actually get what you mean but I'm using jira.js and try to create a ticket like this 

client = new Version3Client({
    host: process.env.JIRA_HOST,
    authentication: {
      basic: {
        username: process.env.JIRA_USERNAME,
        password: process.env.JIRA_PASSWORD,
      },
    },
  });
const issue = await this.client.issues.createIssue({
        fields: {
          summary: fields.summary,
          description: "||Name||||Title|||Tyler||Software Engineer|"
          project: {
            key: fields.projectKey,
          },
          issuetype: {
            name: fields.issueType,
          },
          assignee: {
            id: fields.assignee,
          },
        },
      });

And there are no table is rendered
--------------------------------------------
it work when I tried like 
description: {
"type": "doc",
"version": 1, "
"content" :
{
"type": "table",
"content" : // content goes here


But it take too much configuration, though your way will be more easier but it didn't work

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 23, 2023

Field configuration and renderers are at configuration level and not at request level. https://support.atlassian.com/jira-cloud-administration/docs/configure-renderers/

Tyler Do March 27, 2023

@Fabio Racobaldo _Herzum_  sorry for late response, so I can't add something like 
"||Name||||Title|||Tyler||Software Engineer|"
in my description by request to this api POST /rest/api/3/issue right ? in order to render a table.

If so, where exactly do I need to put/insert them so that I can render a table using your way? I've read the document above but not fully understand it.

Appreciate your help.

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 27, 2023

Hi @Tyler Do ,

probably you need to encode your description before using REST API. (https://www.urlencoder.org/)

Tyler Do April 11, 2023

@Fabio Racobaldo _Herzum_, sorry, just came back after the holiday, but it still doesn't work, appreciate any help from you, thanks.


Rahim T_S
Contributor
June 15, 2023

Will this be helpful for you ?  html-tablify. This worked for me

0 votes
Rahim T_S
Contributor
March 23, 2023

@Tyler Do I moved on to using html-tablify This works 

Suggest an answer

Log in or Sign up to answer