Forums

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

Scriptrunner description field formatting help

Autumn Justice June 8, 2023

Hi!

I'm currently writing a script to auto-populate the description field with info-paneled text on a specific ticket type, using the script runner "behaviors" feature. 

My main issue is that I've got no formal JS training, so something is wonky with my script, but I'm not sure what...I'd appreciate any help with troubleshooting the below code! 

I've attached the screenshots of what I'd like the formatted ticket template to look like, and the main error message I'm getting when writing the code in behaviors (pretty sure I just have no idea how to add multiple parameters one after the other correctly).

 

Thank you for any help here!

 

const descriptionValue = getFieldById("description").getValue();

const descriptionValueContent = descriptionValue.content.toString();

if (!descriptionValueContent) {

getFieldById("description").setValue({

"version": 1,

"type": "doc",

"content": [

{

"type": "panel",

"attrs": {

"panel type": "info"

},

"content": [

{

"type": "paragraph",

"content": [

{

"type": "text",

"text": "Hypothesis:"

}

]

{

},

"type": "panel",

"attrs": {

"panel type": "info"

},

"content": [

{

"type": "paragraph",

"content": [

{

"type": "text",

"text": "Goal:"

}

]

{

},

"type": "panel",

"attrs": {

"panel type": "info"

},

"content": [

{

"type": "paragraph",

"content": [

{

"type": "text",

"text": "Estimated Business Impact:"

}

]

{

},

"type": "panel",

"attrs": {

"panel type": "info"

},

"content": [

{

"type": "paragraph",

"content": [

{

"type": "text",

"text": "Needed By:"

}

]

{

},

"type": "panel",

"attrs": {

"panel type": "info"

},

"content": [

{

"type": "paragraph",

"content": [

{

"type": "text",

"text": "Background/Details:"

}

]

}

]

}

]

});

}

 

Initial error I'm getting returned:

Screen Shot 2023-06-08 at 10.07.39 AM.png

 

Goal for formatted ticket:

Screen Shot 2023-06-08 at 11.18.11 AM.png

5 answers

2 votes
Evgenii
Community Champion
June 8, 2023

include description text to triple quotes

const descriptionValue = getFieldById("description").getValue();
const descriptionValueContent = descriptionValue.content.toString();

if (!descriptionValueContent) {
getFieldById("description").setValue("""very long description
in a few lines
with some variables ${var1} and ${var2} in body""")
}
Tim Perrault
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.
June 8, 2023

Evgeniy answer should be good and just use wiki markup to get the panels and stuff

 

const descriptionValue = getFieldById("description").getValue();
const descriptionValueContent = descriptionValue.content.toString();

if (!descriptionValueContent) {
getFieldById("description").setValue("""
{panel:bgColor=#deebff}
(i) Hypothesis:{panel}"""
)
}
Like Evgenii likes this
1 vote
Kristian Walker _Adaptavist_
Community Champion
February 14, 2024

Hi Autumn,

I can confirm that you need to use Atlassian Document Format when setting the description field.

Atlassian provides the Atlassian Document Format Builder tool, and you can use this to create the formatting you want in the visual editor.

It will then generate the Atlassian Document format Code that you can paste into the script to set the description field.

I hope this helps.

Regards,

Kristian

0 votes
Romain Dubousquet November 5, 2024

Hello guys,

 

Just wanted to let you know that I tested it 5 minutes ago and it works with this code :

 

const descriptionField = getFieldById("description");
const descriptionValue = descriptionField.getValue();

// Check if the description field is empty or not a string
if (!descriptionValue || typeof descriptionValue !== "string") {
    descriptionField.setValue({
        "version": 1,
        "type": "doc",
        "content": [
            {
                "type": "panel",
                "attrs": {
                    "panelType": "info"
                },
                "content": [
                    {
                        "type": "paragraph",
                        "content": [
                            {
                                "type": "text",
                                "text": "Hello world"
                            }
                        ]
                    }
                ]
            }
        ]
    });
}

 

And this is what I got :

Workday people 1.png

 

Hope it helps, have a good day !

0 votes
Jesus Octavio Gutierrez Villegas
Contributor
February 13, 2024

Hello, sorry I have a question, anyone knows how to create a table with Behaviour for my Description field?

Kristian Walker _Adaptavist_
Community Champion
February 14, 2024

Hi Jesus,

To create a table, you will need to use Atlassian Document Format and you can use the Atlassian document format builder tool mentioned in my post above to generate the Atlassian document format code for this.

Regards,

Kristian

0 votes
Autumn Justice June 8, 2023

Also sorry -Can't get this Jira forum to paste the code block with appropriate indents and spacing.

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