Questions for Confluence license has expired.

Please purchase a new license to continue using Questions for Confluence.

Conditional Status synchronization using Status.groovy

 
1
0
-1
Currently I'm using Status.groovy (as documented on https://docs.idalko.com/exalate/display/ED/Status+synchronization+on+Jira+Server#StatussynchronizationonJiraServer-statusSyncExternal) to sync statuses. That's working fine. However, I want to sync a status conditionally. But I'm not sure how to do that. For example, this is the current rule: Status.receive(useRemoteStatusByDefault = true, workflowMapping = [ "Open" : "Under Review", "Accepted" : "Under Review", "Done" : "Fixed", ], resolutionMapping = [:]) I only want to make the last status mapping conditional based on the statement: IF fixVersions != null I guess something like: Status.receive(useRemoteStatusByDefault = true, workflowMapping = [ "Open" : "Under Review", "Accepted" : "Under Review", if (fixVersions != null) { "Done" : "Fixed", ], resolutionMapping = [:]) Any suggestions how this can be done? Thanks!
    CommentAdd your comment...

    1 answer

    1.  
      2
      1
      0

      What about 


      UNTESTED
      def workflowMap = [ 
      	"Open" : "Under Review", 
      	"Accepted" : "Under Review", 
      	"Done" : "Fixed" 
      ]
      
      
      
      if (replica.status.name != "Done" || replica.fixVersions != null) {
         // don't do the status transition when the remote status is 'Done' and the fixVersions is empty
         Status.receive(useRemoteStatusByDefault = true, workflowMap, [:])
      }
      
      
      
      
      1. Berry Kersten

        Great, thanks.

        Unfortunately, it's still doing the transition if the fixVersions is empty. However, I don't see any value for that in the Remote Issues, so it seems to be empty.


      2. Francis Martens (Exalate)

        Maybe it is not really empty, but the value is null.

        Can you add in your code something like


        import com.exalate.api.exception.IssueTrackerException
        
        
        // throw an error to be able to inspect the replicas
        throw new IssueTrackerException("Fixversion = ${replica.fixVersions}")

        This will generate an error.  The details of the error contain the message being sent (at bottom of the page)




      3. Berry Kersten

        Yes indeed, that might be the issue. I've added the additional code, and according to the error

        Script error for issue RI-4844. Details: javax.script.ScriptException: com.exalate.api.exception.IssueTrackerException: Fixversion = []. Error line: Script178.groovy:35

      4. Berry Kersten

        Getting closer... I tried again using 

        if (replica.status.name != "Done" && replica.fixVersions.isEmpty()) {
           Status.receive(useRemoteStatusByDefault = true, workflowMap, [:])
        } 


        But that's not resulting the expected behaviour. I want that (pseudocode)


        IF status DONE AND fixVersions has a value

        OR IF any other status AND fixVersions is empty

        THEN do the workflowmap


        As I'm not a Groovy expert, I'm not sure how to do this. Any suggestions?




      5. Francis Martens (Exalate)

        I guess you're almost there - can you try


        def workflowMap = [ 
        	"Open" : "Under Review", 
        	"Accepted" : "Under Review", 
        	"Done" : "Fixed" 
        ]
        
        
        
        if (replica.status.name != "Done" || replica.fixVersions?.size() > 0) {
           // don't do the status transition when the remote status is 'Done' and the fixVersions is empty
           Status.receive(useRemoteStatusByDefault = true, workflowMap, [:])
        }
      6. Berry Kersten

        Francis Martens (Exalate)


        Thanks for the new suggestion.  However, unfortunately that does not work: when the status is set to Done AND FixVersions is empty, then the sync is performed (including workflowmapping).

        I also tried the operator != but that didn't work as well. Even tried == and < (for testing a negative flow).


        Just thinking out loud Maybe we should include some kind of other check first, like

        def emptyList = fixVersions.isEmpty
        
        if (replica.status.name != "Done" || emptyList = false )



          

      7. Francis Martens (Exalate)

        Yes - this might work - small suggestion ...


        if (replica.status.name  != "Done" || !replica.fixVersions?.isEmpty) ...
      8. Berry Kersten

        I found out that something else was wrong the config...


        The suggestion  if (replica.status.name != "Done" || replica.fixVersions?.size() > 0) {  works!

      CommentAdd your comment...