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:
Goal for formatted ticket:
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""")
}
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}""")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :
Hope it helps, have a good day !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello, sorry I have a question, anyone knows how to create a table with Behaviour for my Description field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also sorry -Can't get this Jira forum to paste the code block with appropriate indents and spacing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.