Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Scriptrunner: setDescription() is not updating the description of the issue

What I want to do - Based on any issue key, select that issue and update the description field with a string.

What happens - In my original script, I print the issue key and string variable to the log before the setDescription(), the log looks fine but the description of the ticket is not updated. 


As only this part was not working in my script, I made the below simplified attempts to figure out how to resolve the problem but even don't get this working. I am probably not pointing to the right issue but I have no clue why the below is not working (I am quite novice)

IssueService issueService = ComponentAccessor.getIssueService();
IssueService.IssueResult issueResult = issueService.getIssue(user,"JP-2")
MutableIssue testIssue = issueResult.getIssue();


MutableIssue testIssue = issueManager.getIssueByKeyIgnoreCase("JP-2")


2 answers

How do you conclude " not working..." ? From The UI where you see the issue ? Or did you add log info just after the setDescription() method ?

Your code is very focussed, but without any context it is difficult to say what is wrong : where do you use such script ? (PostFunction ? Behaviour ?  ... ?) I can's see any saving of you changes in the issue ? (nor re-indexing the issue)...

Hi Marc, thank you very much for your quick response.

Some more info:

- I am writing this script in the script editor and calling the file from a post-function transition in the workflow

- I concluded that is not working based on the issue not being updated in the UI, I created another logline after the setDescription and the description is indeed updated but apparently not saved to the DB.

--> So clearly I have to do something to save the change to the DB to make the change visible in the UI.

I have to use IssueService for this? I am trying some things out but am clearly already past my current skill ceiling so help will be extremely welcome ^^.

My best guess it to somehow use IssueService.AssignValidationResult and IssueService.UpdateValidationResult for this?

Hi, ok, if it is a PostFunction, the order of the PostFunctions is important. You should put your PostFunction before the issue save and re-index postfuinctions.

You should neither instatiate the issue using issueService or issueManager, but use the placeholder "issue" for the issue the PostFunction is working on !

Thanks again Marc!

The script is called as the first step in the PostFunction with the save and re-index taking place after it. The problem here is probably that I am not actually updating the description of the issue that is being transitioned, but updating the description of another issue within the same project (any issue with the value of the key that I input), which probably causes it to not update. 

Background Info:

In my script(s) I am automatically updating the members of groups through two issue types. 1) A 'Group' issue representing a group, its members, group owner, etc. , 2) A permission ticket with the approval flow that triggers the actual adding/removing members in the respective Jira group.

Once members have been added/removed through the permission issue, I need to update the description of the 'Group' issue. I run a JQL query to find the relevant Group issue, get its issue key from it and update some values including the Description field. This is done at a transition of the permission issue (the above PostFunction), but I also have to run the script once a day. That is why the issue key (in the original script) is not static and why I am not updating any values in the permission ticket itself (where the script is called), but on another issue (Group).  

Note: I am currently calling the script from a PostFunction for testing purposes but that I will also call the script on a scheduled basis using an "Automation for Jira" automation rule. I think I cannot use the 'issue.' method as when I do not call the script from a PostFunction, there is not directly an issue related to it.

What I think I need to do now:

So based on your answers and what I checked after, it seems I need to somehow save and re-index the issue that I am updating (which is not the 'current' issue). 

If you could point me in the right direction of what I roughly need to do and which classes/methods to use (using issueService or issueManager?), I will be very grateful :)

Ok, if you want to update another issue than the one your postfunction is working on, you should save your changes and reindex that issue.

Code should be something like

IssueManager issueManager = ComponentAccessor.getIssueManager()
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(user, testIssue, EventDispatchOption.DO_NOT_DISPATCH, false)

Boolean wasIndexing = ImportUtils.isIndexIssues()
IssueIndexingService indexing = (IssueIndexingService) ComponentAccessor.getComponent(IssueIndexingService.class)
Like Ivo_de_Vries likes this

...and to " a script on a scheduled basis..." I would rather use a scripted service...

Like Ivo_de_Vries likes this

Hi Marc, thank you very much for all your help. Didn't get it to work yet but I will fiddle a bit with the code until I get it to do what I want. When I find the solution I will post it here for people struggling with the same problem.

This is quite a big step for me in increased complexity so will need some time to figure out how it works and what those extra lines of codes actually do.

Scripted service is something new for me, will definitely have a look into that!

Thanks again!

EDIT: Got it to work!! Made some newbie mistakes with missing some of the imports :). Extremely happy as this was the last thing to solve in this project!

I had the same problem and got it fixed by putting the function Creates the issue originally. after my scripted function.

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events