2
1
0

We have a JIRA Cloud to JIRA Cloud connector

We went to exclude syncing comments from a specific user for a specific date


Example:  We have comments made by Joe Soap on 24 November 2021 on SystemA

We do not want Joe's comments for that date to sync to SystemB


I know this must be possible via the author comment tag, but no idea how to accomplish this Support 

    CommentAdd your comment...

    1 answer

    1.  
      2
      1
      0

      Hi Charlie Schonken 


      Thanks for your question (and an alternative name for John Doe)

      Assuming you use a scripted connection
      You can filter out the comments from Joe in your outgoing sync by adding

      Untested
      replica.comments = issue.comments.findAll {
      		comment ->
      		comment.author.name != "Joe Soap"
      }



      1. Francis Martens (Exalate)

        PS - whenever in doubt - use the groovy console to try out some constructs
        https://groovyconsole.appspot.com/

      2. Charlie Schonken

        Thank you Francis Martens (Exalate) ,


        ... and the date paranter?

      3. Francis Martens (Exalate)


        You can check on the properties of the comment by adding in the closure


        debug.error("Comment properties = ${comment.properties}")

        Or check the documentation 'Comment'

        And then add the condition such as 


        comment.author.name != "Joe Soap" && comment....

        Give it a try.

      4. Charlie Schonken

        Hi Francis Martens (Exalate) - thank you for the continued assistance.
        Let me frame it ... I am a newbie at this scripting thing, and I fear im not the best at understanding everything.

        I did not know how to "AND" different conditions, which you now highlighted as "&&" ... that is extremely helpful thankyou.

        I noted from the Comment documentation that there is a CREATED property.
        I am not 100% sure how to use it in terms of the date format to be used.

        I want to state that comment.created > "24 November 2021" but not this seems wrong, or is it?
        in other words it must only look at comments after 24 November.

      5. Charlie Schonken

        also the debug thing ... i added it to the script ... but entirely pointless ... it doesnt show me anything meaningful except a error trace ... and all that says is "No such property: comment for class: Script100" on line 18 ... which is the debug line.  So no idea what its supposed to do.

      6. Francis Martens (Exalate)

        OK - 

        "24 november 2021" is not a date but a string and comparing apples with pears is also not possible even if you're a computer.  Luckily our best friend google points to an article

        https://stackoverflow.com/questions/45099374/how-to-compare-date-in-groovy

        for details on how to compare dates.


        Regarding the debug statement - did you add it in the closure like in.  The closure is the block delineated with curly brackets ({}) after findAll

        replica.comments = issue.comments.findAll {
        		comment ->
        		comment.author.name != "Joe Soap"
        
                debug.error("Comment properties = ${comment.properties}")
        }



        I can understand that there is a learning curve to go through scripting.

        There are resources available online to learn on how to do such things, or exalate has today 126 partners which can help with the implementation and get your integration configured faster than writing up the whole thread.



      7. Charlie Schonken

        Hi Francis Martens (Exalate) 

        Sorry ... maybe it's me.

        I have now literally copied your script from above


        replica.comments = issue.comments.findAll {
        		comment ->
        		comment.author.name != "Joe Soap"
        
                debug.error("Comment properties = ${comment.properties}")
        }

        and now I still get an error saying No such property: name for class: com.exalate.basic.domain.hubobject.v1.BasicHubUser on line 19 ... 


        Line 19 is the comment.author condition


        Maybe the app just doesnt like me (sad)

      8. Francis Martens (Exalate)

        Let's no go there, we get in trouble if computers starts to have feelings.

        The reason why it doesn't work is because author.name doesn't exist.  I made the mistake not to look up the attributes for a user (here)


        It should be comment.author.displayName ...
        (I didn't tested my suggestion)

      9. Charlie Schonken

        lol (big grin) Francis Martens (Exalate) 

        Humor helps.


        Ok, I have now edited the script as follows ...

        replica.comments = issue.comments.findAll {
          comment ->
          comment.author.displayName != "BigPicture - for ppm, project management" && comment.created > new Date().parse("dd MMM yyyy HH:mm:ss", "25 Nov 2021 00:00:01")
        
                debug.error("Comment properties = ${comment.properties}")
        }

        Note: Excluding comments from BigPicture, and only including comments after 25 November 2021 00:00:01


        And now I am getting the error ...

        No signature of method: java.util.Date.parse() is applicable for argument types: (String, String) values: [dd MMM yyyy HH:mm:ss, 25 Nov 2021 00:00:01] Possible solutions: parse(java.lang.String), wait(), clone(), any(), grep(), use(java.lang.Class, groovy.lang.Closure)


        ... so assuming its something to do with the date check I am doing.  The date format piece you directed me to had the following example ...

        //Define the date format as per your input
        def df = "dd.MM.yyyy HH:mm:ss,S"
        
        //Parse the date string with above date format
        def dateTime1 = new Date().parse(df, "13.07.2017 14:03:51,469000000")
        def dateTime2 = new Date().parse(df, "13.07.2017 14:03:52,469000000")
        
        //Compare both date times
        assert dateTime1 < dateTime2


        Instead of defining the format, I opted to put it directly in the parse string, replacing the df variable.  If Groovy is like any other language, this should work.  So, I missed something obviously.  The assertAlthough the error seems to be more concerned with the parse than the missing assert.

        This is getting complex ... my brain is tired now


        Here is the debug, without the parse ...

        Comment properties = [created:Wed Aug 18 11:00:00 UTC 2021, roleLevel:null, executor:null, traceType:COMMENT, class:class com.exalate.basic.domain.hubobject.v1.BasicHubComment, updated:Wed Aug 18 11:00:00 UTC 2021, id:501774, idStr:501774, locked:false, groupLevel:null, remoteId:null, updateAuthor:{ @key : 557058:7a06e294-0e9a-4c87-8aac-cd79ff369b03}, restrictSync:false, remoteIdStr:null, internal:false, body:Only phase 1 if using tasks in SKi. Currently managed in SF, author:{ @key : 557058:7a06e294-0e9a-4c87-8aac-cd79ff369b03}]



        Saskia sorry to push your button, I know I probably have to log a ticket, but at this point I need someone just to script it for me ... I have spent the entire day on this already.

      10. Charlie Schonken

        Saskia pls can I have help on this

      11. Francis Martens (Exalate)

        Found some time to look into this one.

        Following works.  Note that if you add ',S' into the pattern - the thing behind the ',' is added to the timestamp.  So 469000000 is equivalent to 5 days and some


        Outgoing sync | Tested
        import java.text.SimpleDateFormat
        // only comments after Jan 12, 2022
        
        def df = "dd.MM.yyyy HH:mm:ss"
        def limitDate = new SimpleDateFormat(df).parse("12.01.2022 14:03:51")
        def limitTimeStamp = limitDate.getTime()
        
        replica.comments = issue.comments.findAll {
        		comment ->
        		comment.author.displayName != "Joe Soap" && comment.created?.getTime() >= limitTimeStamp
        }
        
        
        


        Give it a try and let me know

      12. Charlie Schonken

        Hi Francis Martens (Exalate) ,


        Before I implement, one question.


        I currently have the comments configured to only share public comments

        replica.comments       = issue.comments.findAll { !it.internal }

        Will this new script still only share public comments after a certain date, or will it now share ALL comments?  It is a risk for me, as the destination is external.  Does it need to be edited to still make sure its only public comments?


        Do I just add it after the timestamp?


        import java.text.SimpleDateFormat
        // only comments after Jan 12, 2022
        
        def df = "dd.MM.yyyy HH:mm:ss"
        def limitDate = new SimpleDateFormat(df).parse("12.01.2022 14:03:51")
        def limitTimeStamp = limitDate.getTime()
        
        replica.comments = issue.comments.findAll {
        		comment ->
        		comment.author.displayName != "Joe Soap" && comment.created?.getTime() >= limitTimeStamp && !it.internal
        }
      13. Francis Martens (Exalate)

        Better to use 


        ... && !comment.internal

        Syntactical your suggestion is correct, but less readable (smile)

      14. Charlie Schonken

        busy testing ... will advise

        Much appreciated Francis Martens (Exalate) 

      15. Francis Martens (Exalate)

        You're welcome and thank you for the patience.

      CommentAdd your comment...