Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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 Issue Picker current value

We updated the Scriptrunner from 5.9.0. to 6.7.0. and we detected an issue in our post function. The function is about comparing issue pickers current and previous value with each other then change the issue accordingly, but when we try to get the issuepicker custom field value after transition (post function runs in first place) we only get the previous value. I tried to move the function after 'Update change history for an issue and store the issue in the database.' phase: when I did this, I got the current value and with changehistory the previous value to compare them, but if I change something in the issue with this script, it doesn't change.

Is anyone familiar with this problem? I'm thinking that reindexing the issue is a way, but it doesn't feel right, especially since this function worked perfectly before the update.

1 answer

Hi @Andrea Veres 
How are you saving your issues modifications?

What do you mean, you should save it in a post script if it's the main issue? Here's a snippet of my code.

 

def selectCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects(issue).find {it.name == "issuPickerFieldName"}
Issue selectIssue = issue.getCustomFieldValue(selectCustomField) as Issue
def changes = ComponentAccessor.getChangeHistoryManager().getChangeItemsForField(issue, "issuPickerFieldName")
Issue oldIssue = changes.size() == 0 ? null : issueManager.getIssueObject(changes?.last()?.getFromString())

def numCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects(issue).find {it.name == "numberFieldToChange"}

if (oldIssue != null && selectIssue == null) {
issue.setCustomFieldValue(numCustomField, null)
if (issueLinkManager.getIssueLink(oldIssue.getId(), issue.getId(), 10801) != null) {
issueLinkManager.removeIssueLink(issueLinkManager.getIssueLink(oldIssue.getId(), issue.getId(), 10801), user)
}
}
else if (oldIssue == null && selectIssue != null) {
def compNumCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects(selectIssue).find {it.name == 'numberField'}
String currentCompNum = selectIssue.getCustomFieldValue(compNumCustomField)

issue.setCustomFieldValue(numCustomField, currentCompNum)

issueLinkManager.createIssueLink(selectIssue.getId(), issue.getId(), 10801, 1, user)
}
else if (oldIssue != null && selectIssue != null && oldIssue.getId() != selectIssue.getId()) {
if (issueLinkManager.getIssueLink(oldIssue.getId(), issue.getId(), 10801) != null) {
issueLinkManager.removeIssueLink(issueLinkManager.getIssueLink(oldIssue.getId(), issue.getId(), 10801), user)
}

def compNumCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects(selectIssue).find {it.name == 'numberField'}
String currentCompNum = selectIssue.getCustomFieldValue(compNumCustomField)

issue.setCustomFieldValue(numCustomField, currentCompNum)

issueLinkManager.createIssueLink(selectIssue.getId(), issue.getId(), 10801, 1, user)
}

Sorry, I meant if you were using a method like "updateIssue" or an Issue Service.

e.g 

IssueManager issueManager = ComponentAccessor.getIssueManager()
issueManager.updateIssue(user,issue,EventDispatchOption.DO_NOT_DISPATCH,false)

I usually do not, because if I modify the issue before 'Update change history for an issue and store the issue in the database.' phase in transition, it will be automaticly updated. I asked this question to know that it's the issue pickers designed behaviour. I will try out this update method. Thank you!

Ok, I usually leave it on the last phase, that's why I need the update.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

367 views 2 2
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