Forums

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

ScriptRunner custom listener updates field in linked issue but doesn't show the issue as updated

Mike Rathwell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2018

With all the preamble code that makes the following work, the listener will always get the destination (outward) linked issues of a certain link type and update fields appropriately in them. HOWEVER, it never shows "updated just now" or reflects in the history or activity. What am I missing? I've grepped google for how to fire an event but can't seem to get what I am looking for. This is with Jira 7.8.2 and ScriptRunner 5.4.12. I get no failures but it just doesn't seem to fire an event for the target issue that it was updated.

 def changeHolder = new DefaultIssueChangeHolder()
startDateField.updateValue(null, linkedIssue, new ModifiedValue(linkedIssue.getCustomFieldValue(startDateField), newDate), changeHolder)
issueManager.updateIssue(null, linkedIssue, EventDispatchOption.ISSUE_UPDATED, true)

 

3 answers

2 accepted

0 votes
Answer accepted
Tansu Akdeniz
Community Champion
August 7, 2018

Hi @Mike Rathwell,

Try to update linked issue's value with this code, not using changeHolder.

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
linkedIssue.setCustomFieldValue(startDateField,newDate)
issueManager.updateIssue(user, linkedIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
Vineela Durbha
Contributor
April 4, 2019

@Mike Rathwell 

What is linkedIssue here?

Mike Rathwell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 4, 2019

Hi @Vineela Durbha 

That linked issue is defined earlier in the script where I am getting outward links from the current issue being worked on. The code looks like this:

 List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
MutableIssue linkedIssue = issueLink.getDestinationObject() as MutableIssue;
0 votes
Answer accepted
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2018

Hello,

You use the updateValue() method that is why the history is not generated. It should be like this:

linkedIssue.setCustomFieldValue(startDateField, newDate) 
issueManager.updateIssue(null, linkedIssue, EventDispatchOption.ISSUE_UPDATED, true)

You can read about updating issues in Jira in my article:

https://community.atlassian.com/t5/Agile-articles/Three-ways-to-update-an-issue-in-Jira-Java-Api/ba-p/736585

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 8, 2018

Try the answer of @Tansu Akdeniz. Concerning your question. You can not see history because UpdateValue does not generate history. It is written in my article

Mike Rathwell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 8, 2018

Thanks Alexey... As I noted in my rather large script, now that I grok this better with your help, I ended up using both as there is one case in the script that I want it to put in the history... and another that I don't... for reasons... 

Thanks for you help and attention to my plight

Best,

Mike

0 votes
Mike Rathwell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 8, 2018

@Alexey Matveev and @Tansu Akdeniz, thank you both. I had looked at the "setCustomFieldValue()" call and I guess I read it upside down. To get it clear in my (admittedly tiny) mind:

  • My attempt was, in fact updating the value and writing to the database. However:
    • the updateValue() updated in the database
    • the following updateIssue() did what it should BUT since there were no pended changes... it did nothing.
  • Your suggestions (which worked):
    • setCustomeFieldVAlue() sets the value but does NOT push to the DB
    • the subsequent updateIssue() sees the change and commits to the database and flags the just updated and updates the history.

I am going to try to accept BOTH your recommendations as the answer but if not, will upvote both of you. I ended up using Alexey's updateIssue() params in one place in my script and Tansu's in another.

 

Thank you both!

Suggest an answer

Log in or Sign up to answer