Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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();
testIssue.setDescription("Test")

OR

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

 

1 answer

How do you conclude "...is 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)
indexing.reIndex(testIssue)
ImportUtils.setIndexIssues(wasIndexing)
Like Ivo_de_Vries likes this

...and to "...call 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!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Jira Cloud Performance Improvements

Hello everyone, I am a product manager in the Jira Cloud team focused on making sure our customers have a delightful experience using our products. Towards that goal, one of the areas which is extr...

171 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you