Forums

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

setDescription in Scriptrunner updates scriptrunner log but not the actual issue description

Amed Moreno February 20, 2023

Hello Community,

Using seemingly simple setDescription in Scriptrunner updates scriptrunner log but not the actual issue description

2023-02-20 13_36_26-Script Console.png

Any help greatly appreciated.

Thank you

1 answer

1 accepted

0 votes
Answer accepted
Italo Lobato Qualisoni February 20, 2023

Hi @Amed Moreno ,

Did you try using Automation for JIRA? It's way lighter experience to automate your workflow and its native on JIRA Cloud and DC environment. You can learn more bout Automation for JIRA on below webinar:

https://events.atlassian.com/unleash/v/s-1268659

About your question when you invoke the setSummary function it changes the Issue Object but it does not write to the database the updated summary version.

In order to update the summary you might need to use the IssueService which provides a method to update an issue (https://docs.atlassian.com/software/jira/docs/api/9.4.0/com/atlassian/jira/bc/issue/IssueService.html#update-com.atlassian.jira.user.ApplicationUser-com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult-).

See examples:

I didn't test but the following code might work,

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueInputParametersImpl

// the issue key to update
final String issueKey = "PLAYG-7"

// change to 'true' if you want to send an email if the update is successful
final boolean sendMail = false

def issueService = ComponentAccessor.issueService
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey(issueKey)

assert issue : "Could not find issue with key $issueKey"

def issueInputParameters = new IssueInputParametersImpl()
issueInputParameters.setDescription("New Description")
def updateValidationResult = issueService.validateUpdate(loggedInUser, issue.id, issueInputParameters)
assert updateValidationResult.valid : updateValidationResult.errorCollection
def issueUpdateResult = issueService.update(loggedInUser, updateValidationResult, EventDispatchOption.ISSUE_UPDATED, sendMail)
assert issueUpdateResult.valid : issueUpdateResult.errorCollection
Amed Moreno February 23, 2023

@Italo Lobato Qualisoni 

Hi Italo,

Thank you for the response and help.  Yes, I know of Automation for Jira and use often.  I am trying to learn Scriptrunner so posting to gain knowledge on the subject.

I still have a lot to learn.  That script is very complex for just setting a description and can see why you suggested Automation for Jira.

Thanks again and Kind Regards,

Amed

Italo _Modus Create_
Contributor
February 24, 2023

 

Take a look on the new feature released this week for Scriptrunner DC called HAPI, it simplies the code required to do what you are looking for.

 

def issue = Issues.getByKey('ABC-1')

issue.update {
   setSummary('an updated summary')
   setDescription('hello *world*')
}
You need to update the Scriptrunner app to the latest version in order to use this new feature. 
Like Jonny Carter likes this
Amed Moreno February 24, 2023

@Italo _Modus Create_ 

Wow!  Awesome Italo!  I will be checking this out.

Thanks again!  

Suggest an answer

Log in or Sign up to answer