defaultValue for the Description remains after change of ticket type
Asked by Salim Hammar:

Hello

In my Jira Cloud i have created 2 behaviours for set a diferents description in the system field description in two issue type but in the screen creation when i switch the issue type story to Epic and the description dont change

Behaviour n?1 :

Issue Type = Story

Description = "hello set your name : "

Behaviour n?2 :

Issue Type = Epic

Description = "give me your reference : "

This is my script :

------------------------------START SCRIPT-----------------------------------------------

const descriptionValue = getFieldById("description").getValue();  
// If description field is wiki markup access the content property  
if (typeof descriptionValue !== "string") {  
const descriptionValueContent = descriptionValue.content.toString();  
if (!descriptionValueContent) {  
getFieldById("description").setValue({  
"version": 1,  
"type": "doc",  
"content": \[  
{  
"type": "paragraph",  
"content": \[  
{  
"type": "text",  
"text": "? Hello set your name : "  
}  
\]  
},  
{  
"type": "table",  
"attrs": {  
"isNumberColumnEnabled": false,  
"layout": "default",  
"localId": "ee831789-6c04-4882-9b22-69e71e2ccfff",  
"width": 760  
},  
"content": \[  
{  
"type": "tableRow",  
"content": \[  
{  
"type": "tableHeader",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
},  
{  
"type": "tableHeader",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
},  
{  
"type": "tableHeader",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
}  
\]  
},  
{  
"type": "tableRow",  
"content": \[  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
},  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
},  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
}  
\]  
},  
{  
"type": "tableRow",  
"content": \[  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
},  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
},  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
}  
\]  
}  
\]  
}  
\]  
}  
)  
}  
}  
---------------------------------END SCRIPT-------------------------------------------------  
You have idea ?  
Thanks in advance


Answers:
author: Sean Chua _Adaptavist_
body: Hey [@Salim Hammar](/t5/user/viewprofilepage/user-id/5574972) , Welcome to Atlassian Community.  

You probably have to do a call to wait for context. Try something like this and see if it works with just words.

    const context = await getContext();
    const issueType = context.extension.issueType.name;
    const descriptionField = getFieldById("description");

    let descriptionText;
    if (issueType === "Story") {    descriptionText = "hello set your name :";} else if (issueType === "Epic") {    descriptionText = "give me your reference :";} else {
    //default text    descriptionText = "Any other default description if needed."; 
    }

    descriptionField.setValue({    "version": 1,    "type": "doc",    "content": [        {            "type": "paragraph",            "content": [                {                    "type": "text",                    "text": descriptionText,                }            ]        }    ]});

It looks like you are trying to also put in a table there. You can check out the ADF format samples from [Create HTML Table with Issue Details](https://library.adaptavist.com/entity/rich-text-table?tab=cloud) .

Hope this helps!

comments: author: Salim Hammar
body: Hello [@Sean Chua _Adaptavist_](/t5/user/viewprofilepage/user-id/5189356)

it worked, thank you boss ;)


author: Salim Hammar
body: Hi [@Sean Chua _Adaptavist_](/t5/user/viewprofilepage/user-id/5189356)

i would like to set this :

**![2024-08-29 16_57_22-Document builder.png](https://community.atlassian.com/t5/image/serverpage/image-id/344582i81F7A431064E12C7/image-size/large?v=v2&px=999 "2024-08-29 16_57_22-Document builder.png")**

Can you help me to set this in the script that you have send me , the script for this table generated here : [Document builder](https://developer.atlassian.com/cloud/jira/platform/apis/document/playground/)

this is script you can you generate this table in the link :

{  
"version": 1,  
"type": "doc",  
"content": \[  
{  
"type": "table",  
"attrs": {  
"isNumberColumnEnabled": false,  
"layout": "default",  
"localId": "5c42930a-af01-4057-bd6b-c0fb86e94486",  
"width": 760  
},  
"content": \[  
{  
"type": "tableRow",  
"content": \[  
{  
"type": "tableHeader",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[  
{  
"type": "text",  
"text": "test 1",  
"marks": \[  
{  
"type": "strong"  
}  
\]  
}  
\]  
}  
\]  
},  
{  
"type": "tableHeader",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[  
{  
"type": "text",  
"text": "test 2",  
"marks": \[  
{  
"type": "strong"  
}  
\]  
}  
\]  
}  
\]  
},  
{  
"type": "tableHeader",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[  
{  
"type": "text",  
"text": "test 3",  
"marks": \[  
{  
"type": "strong"  
}  
\]  
}  
\]  
}  
\]  
}  
\]  
},  
{  
"type": "tableRow",  
"content": \[  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
},  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
},  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
}  
\]  
},  
{  
"type": "tableRow",  
"content": \[  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
},  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
},  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
}  
\]  
}  
\]  
},  
{  
"type": "paragraph",  
"content": \[\]  
}  
\]  
}

Thanks in advance for your help boss ;)

comments: author: Sean Chua _Adaptavist_
body: Hey [@Salim Hammar](/t5/user/viewprofilepage/user-id/5574972) ,

to set the ADF, you can use something like this below. The format doesn't look pretty as I'm just copy pasting from another sample I had, I am generalising for all issuetypes, you will need to set the issuetype requirements etc.

const context = await getContext();  
const issueType = context.extension.issueType.name;  
const descriptionField = getFieldById("description");

const descriptionContent = {  
"version": 1,  
"type": "doc",  
"content": \[  
{  
"type": "table",  
"attrs": {  
"isNumberColumnEnabled": false,  
"layout": "default"  
},  
"content": \[  
{  
"type": "tableRow",  
"content": \[  
{  
"type": "tableHeader",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[  
{  
"type": "text",  
"text": "Test 1",  
"marks": \[  
{  
"type": "strong"  
}  
\]  
}  
\]  
}  
\]  
},  
{  
"type": "tableHeader",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[  
{  
"type": "text",  
"text": "Test 2",  
"marks": \[  
{  
"type": "strong"  
}  
\]  
}  
\]  
}  
\]  
},  
{  
"type": "tableHeader",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[  
{  
"type": "text",  
"text": "Test 3",  
"marks": \[  
{  
"type": "strong"  
}  
\]  
}  
\]  
}  
\]  
}  
\]  
},  
{  
"type": "tableRow",  
"content": \[  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[  
{  
"type": "text",  
"text": "Row 1, Cell 1"  
}  
\]  
}  
\]  
},  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[  
{  
"type": "text",  
"text": "Row 1, Cell 2"  
}  
\]  
}  
\]  
},  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[  
{  
"type": "text",  
"text": "Row 1, Cell 3"  
}  
\]  
}  
\]  
}  
\]  
},  
{  
"type": "tableRow",  
"content": \[  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[  
{  
"type": "text",  
"text": "Row 2, Cell 1"  
}  
\]  
}  
\]  
},  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[  
{  
"type": "text",  
"text": "Row 2, Cell 2"  
}  
\]  
}  
\]  
},  
{  
"type": "tableCell",  
"attrs": {},  
"content": \[  
{  
"type": "paragraph",  
"content": \[  
{  
"type": "text",  
"text": "Row 2, Cell 3"  
}  
\]  
}  
\]  
}  
\]  
}  
\]  
}  
\]  
};  
descriptionField.setValue(descriptionContent);

It should look like this:  
![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/345053i56871D6E096142A5/image-size/large?v=v2&px=999 "image.png")


Tags: behaviours

cloud

jira-cloud

scriptrunner