How to discard transaction updates

Guilherme Nogueira
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 21, 2015

Hi,

 

I have a transition that creates an issue in another project - OK.

But in this transition I have some fields that can be modified by user and the issue that i'll create will take this value. The problem is, I want to discard this field, I don't want to save it on original issue, only on new issue.

I want to keep original issue value independently what was edited during transition

Is that possible?

 

Thanks

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Guilherme Nogueira
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 21, 2015

I got it!!

 

There's a code that checks only one multi checkbox field and compare old value and new and always keep the old value.

If someone need help contact me.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.context.IssueContext
import com.atlassian.jira.issue.context.IssueContextImpl
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import java.util.ArrayList
import java.util.Arrays
 

 
Issue issue = issue

IssueChangeHolder changeHolder = new DefaultIssueChangeHolder()
 
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def customField = customFieldManager.getCustomFieldObjectByName("Flags")
def originalIssue = issueManager.getIssueObject(issue.id)
def componentManager = ComponentManager.instance
def optionsManager = componentManager.getComponentInstanceOfType(OptionsManager.class)

ArrayList old = originalIssue.getCustomFieldValue(customField)


if(customField!=null){
def fieldConfig = customField.getRelevantConfig(issue)
ArrayList yes 

for(String flag: old){
 if (yes == null){
 yes = [optionsManager.getOptions(fieldConfig).getOptionForValue(flag,null)] 
 }else{ 
 yes = yes + [optionsManager.getOptions(fieldConfig).getOptionForValue(flag,null)] 
 }
}
issue.setCustomFieldValue(customField,yes)
}
1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2015

The problem you have is that a transition applies to the current issue you are working with.  It's not intended to work with other issues, just the current one.  So, any field you present to the user is for the current issue.

I suspect the only way you can deal with this is to have your field(s) for the new issue on both the current and new issue and on the screen for the user, use what the user enters to create the new issue, and then actively discards the data from the current issue in the same post-function that creates the new issue.

Guilherme Nogueira
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 21, 2015

"and then actively discards the data from the current issue in the same post-function that creates the new issue." this is what I want... how can I do that?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2015

In your code, add something to clear the fields on the current issue.

Guilherme Nogueira
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 21, 2015

I don't want to clear, I want to keep the old value, before I executed my transition

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2015

Mmm, that wasn't really mentioned before, but yes, you have options: You could use different fields completely. So the current issue has a field called say "Colour" (for example) and then you have "Spawned Colour" on both current and new issue (and scrub the "Spawned Colour" from the current issue after creating the new issue) Or, if you want to have the same field on new and current issue, then your code needs to be a bit complex. During the post-function, you do actually have access to the previous values on the issue, so you can re-read those and put them back over the top of the new values for the current issue. There is a big problem with your approach there. As a user, I'm offered some fields during a transition. I set two of them. When I commit my transition, one of them is saved and the other is not (because you've taken the old value and destroyed my change). That is going to cause your users a lot of concerns...

Guilherme Nogueira
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 21, 2015

I'm working in a code right now that check if a specific field was edited (only one field) and updates it with the old value. I got your answer thank you.

Guilherme Nogueira
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 21, 2015

I appreciate your answer but it isn't what I'm looking for, upvoted but not accepted. Thank you.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2015

Problem is that there is no other way to do it.

TAGS
AUG Leaders

Atlassian Community Events