Script Runner Behaviours replace existing value of Description field when click on Edit button

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 22, 2022

Hi Guys,

Need one help in fixing the below issues.

I have applied a Script Runner on Description field for Bug issue type, when user click on Create button Default value add in system Description field. In Default value, user there value as well and click create issue. 

When user click on Edit button, Default description set via Behaviour replace the existing value of Description. How can i fix this, so that when user click on Edit button existing value doesn't change nor apply Default description value. 

Want to apply Behaviour only on Create screen. 

 

@Ram Kumar Aravindakshan _Adaptavist_ 

1 answer

1 accepted

3 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 22, 2022

Hi @Vikrant Yadav

From your description, it appears that you need to include the condition

if (!underlyingIssue?.description) {
desc.setFormValue(value)

}

This is so that it will take effect only on the Issue creation screen and not on the Issue update screen, as shown in the Adaptavist Documentation.

It would be good if you could share your code so I can better understand what you are currently doing.

Thank you and Kind regards,

Ram

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 22, 2022

Hi @Ram Kumar Aravindakshan _Adaptavist_  Thanks for your help as always. 

It's working fine now, not editing existing value when clicking on Edit button.

Kindly correct my code, if anything wrong in my code. Following is working for Bug and Bug Subtask.

 

import com.atlassian.jira.issue.*

def description = getFieldById("description")

 

def issuetype = getIssueContext().getIssueType().name

if (issuetype.contains("Bug") || issuetype.contains("Bug sub-task")){

    if (!underlyingIssue?.description){

    description.setFormValue("""h3.Description

_<Explain the observations as clear as possible>_

*Steps to reproduce*

_<-- minimum steps that describe the entire path of reproducing the bug._

_-- Describe one step per line>_

*Expected result*

_<Describe the expected result according to the technical task, design, test cases outcome>_

*Actual result*

_<Explain the current observation as clear as possible>_

*Attachments (screenshots, files, error log etc)*

_-- Screenshot (it's convenient when the bug is highlighted with a circle or an arrow),_

_-- Files (Uploaded files)_

_-- Error logs_

h4.NOTE (optional)

_-- Any other observations_""")

}

}
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 6, 2022

Hi @Vikrant Yadav

You may want to clean up your code a little. You should update it to:-

 

import com.atlassian.jira.issue.*

def description = getFieldById("description")

def issuetype = issueContext.issueType.name

if(!underlyingIssue.description && issuetype in ['Bug', 'Bug sub-task'] ) {

description.setFormValue("""h3.Description

_<Explain the observations as clear as possible>_

*Steps to reproduce*

_<-- minimum steps that describe the entire path of reproducing the bug._

_-- Describe one step per line>_

*Expected result*

_<Describe the expected result according to the technical task, design, test cases outcome>_

*Actual result*

_<Explain the current observation as clear as possible>_

*Attachments (screenshots, files, error log etc)*

_-- Screenshot (it's convenient when the bug is highlighted with a circle or an arrow),_

_-- Files (Uploaded files)_

_-- Error logs_

h4.NOTE (optional)

_-- Any other observations_""")

}
I hope this helps to answer your question. :)
Thank you and Kind regards,
Ram
Like Vikrant Yadav likes this

Suggest an answer

Log in or Sign up to answer