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
Community moderators have prevented the ability to post new answers.
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) }
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In your code, add something to clear the fields on the current issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't want to clear, I want to keep the old value, before I executed my transition
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I appreciate your answer but it isn't what I'm looking for, upvoted but not accepted. Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Problem is that there is no other way to do it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.