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

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

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

203 views 2 5
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