You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hello, got very specific use case and finding a lot of dead ends.
I got two insight field, multi object field.
Lets say we have SourceField and TargetField.
The SourceField is present on transition screen.
The TargetField is hidden, just field for the logic behind.
What I need is:
When I execute the transition, the SourceField already contain object(s).
After I execute the transition I need to copy the objects into the TargetField, but only the new added values, during the transition.
Cannot use the TargetField, as it is handled and updated by another scripted logic behind and could be even empty.
Was thinking about originalIssue, but it doesnt work for me.
Any ideas?
Cheers, Tom
Here is my code I trying currently to run:
The general target is approval process, where manager can edit pending persons (represented by insight objects) by both add new and remove.
When adding, user or group should appear in PENDING field.
When removing, user or group should disappear from all PENDING, APPROVED and DECLINED.
Its quite complex, but generally, what we need is:
Source Field have value [PERSON A]
During transition you will add to that custom field also PERSON B, so during transition it will look like [PERSON A, PERSON B]
When we need, that only PERSON B will be copied to the Target Field.
What we have, it that both PERSON A and PERSON B are copied to Target Field.
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.util.DefaultIssueChangeHolder; import com.atlassian.jira.issue.ModifiedValue; def members = [] Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade") def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass) def customFieldManager = ComponentAccessor.getCustomFieldManager() def changeHolder = new DefaultIssueChangeHolder() //--------------------------- MAIN ELEMENT DEFINITION ------ def fawi = issue.get("customfield_18201") // 1st approval wave individuals BUFFER def fawiP = issue.get("customfield_18207") // 1st approval wave individuals Pending def fawiA = issue.get("customfield_18209") // 1st approval wave individuals Approved def fawiD = issue.get("customfield_18208") // 1st approval wave individuals Declined def fawg = issue.get("customfield_18200") // 1st approval wave groups BUFFER def fawgP = issue.get("customfield_18204") // 1st approval wave groups Pending def fawgA = issue.get("customfield_18205") // 1st approval wave groups Approved def fawgD = issue.get("customfield_18206") // 1st approval wave groups Declined def sawi = issue.get("customfield_18203") // 2nd approval wave individuals BUFFER def sawiP = issue.get("customfield_18213") // 2nd approval wave individuals Pending def sawiA = issue.get("customfield_18214") // 2nd approval wave individuals Approved def sawiD = issue.get("customfield_18215") // 2nd approval wave individuals Declined def sawg = issue.get("customfield_18202") // 2nd approval wave groups BUFFER def sawgP = issue.get("customfield_18210") // 2nd approval wave groups Pending def sawgA = issue.get("customfield_18211") // 2nd approval wave groups Approved def sawgD = issue.get("customfield_18212") // 2nd approval wave groups Declined def sawiAcf = customFieldManager.getCustomFieldObject("customfield_18214") def sawiDcf = customFieldManager.getCustomFieldObject("customfield_18215") def sawiPcf = customFieldManager.getCustomFieldObject("customfield_18213") def fawiAcf = customFieldManager.getCustomFieldObject("customfield_18209") def fawiDcf = customFieldManager.getCustomFieldObject("customfield_18208") def fawiPcf = customFieldManager.getCustomFieldObject("customfield_18207") def sawgAcf = customFieldManager.getCustomFieldObject("customfield_18211") def sawgDcf = customFieldManager.getCustomFieldObject("customfield_18212") def sawgPcf = customFieldManager.getCustomFieldObject("customfield_18210") def fawgAcf = customFieldManager.getCustomFieldObject("customfield_18205") def fawgDcf = customFieldManager.getCustomFieldObject("customfield_18206") def fawgPcf = customFieldManager.getCustomFieldObject("customfield_18204") //-------------------------------- //--- FIRST WAVE GROUP CLEARANCE members = [] members = [fawgP,fawgA,fawgD].flatten() // Loading all decision makers members = members.findAll() if (members == []) {members = null} if (members){ if (!(members?.sort() == fawg?.sort())) { // Sort if (fawg) {members = members?.minus(fawg)} // Looking for removed decision makers fawgP?.removeAll(members) // Removing removed DM fawgA?.removeAll(members) fawgD?.removeAll(members) }} if (fawgA == []) {fawgA = null} fawgAcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fawgAcf), fawgA), changeHolder); if (fawgD == []) {fawgD = null} fawgDcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fawgDcf), fawgD), changeHolder); if (fawgP == []) {fawgP = null} fawgPcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fawgPcf), fawgP), changeHolder); // zapísanie výsledkov späť do decision polí //--- FIRST WAVE INDIVIDUALS CLEARANCE members = [] members = [fawiP,fawiA,fawiD].flatten() members = members.findAll() if (members == []) {members = null} if (members) { if (!(members?.sort() == fawi?.sort())) { if (fawi) {members = members?.minus(fawi)} fawiP?.removeAll(members) fawiA?.removeAll(members) fawiD?.removeAll(members) }} if (fawiA == []) {fawiA = null} fawiAcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fawiAcf), fawiA), changeHolder); if (fawiD == []) {fawiD = null} fawiDcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fawiDcf), fawiD), changeHolder); if (fawiP == []) {fawiP = null} fawiPcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fawiPcf), fawiP), changeHolder); //--- SECOND WAVE INDIVIDUALS CLEARANCE members = [] members = [sawiP,sawiA,sawiD].flatten() members = members.findAll() if (members == []) {members = null} if (members){ if (!(members?.sort() == sawi?.sort())) { if (sawi) {members = members?.minus(sawi)} sawiP?.removeAll(members) sawiA?.removeAll(members) sawiD?.removeAll(members) }} if (sawiA == []) {sawiA = null} sawiAcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(sawiAcf), sawiA), changeHolder); if (sawiD == []) {sawiD = null} sawiDcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(sawiDcf), sawiD), changeHolder); if (sawiP == []) {sawiP = null} sawiPcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(sawiPcf), sawiP), changeHolder); //--- SECOND WAVE GROUP CLEARANCE members = [] members = [sawgP,sawgA,sawgD].flatten() members = members.findAll() if (members == []) {members = null} if (members){ if (!(members?.sort() == sawg?.sort())) { if (sawg) {members = members?.minus(sawg)} sawgP?.removeAll(members) sawgA?.removeAll(members) sawgD?.removeAll(members) }} if (sawgA == []) {sawgA = null} sawgAcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(sawgAcf), sawgA), changeHolder); if (sawgD == []) {sawgD = null} sawgDcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(sawgDcf), sawgD), changeHolder); if (sawgP == []) {sawgP = null} sawgPcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(sawgPcf), sawgP), changeHolder);
Maybe @David Fischer _Appfire_ ? Any ideas? I tried also JMWE copy field to field with append only new values, but did not get expected results.
Hi @Tomáš Vrabec ,
first of all, if you're running this code inside a Scripted (Groovy) post-function, you should use JMWE's simplified API, especially when writing to the field (using the {{issue.setFieldValue}} method).
As for helping you, you'd need to post a minimal script that focuses on the problem at hand (identifying changes to the source field) instead of your long and complicated script... However, I don't actually see how you could get the previous value of your Insight custom field. Did you try using the issue history, and moving the post-function to the bottom of the list? Maybe Insight will write an entry in the issue history for its field, and you can thus see the change made by the user (between "from" and "to")? To access the issue history, you can use issue.getFieldHistory()
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.