Help with parsing text from last comment field to the end of summary field

Issue #123 resolved
Shai Dahan created an issue

Hello Fidel,

I wonder if you can help me again with parsing text from last comment field. I need to add the string {Request #?#} to the end of the summary field. In this case I will always receive a comment with my summary field + {Request #?#} which than I want to amend my field to be exactly the same.

For example Original summary is: "GI (GI-13818) - aplastic - bingo test account - cant log in - Tech" Comment came as an email with the subject line: "Subject: RE: [GCI Jira] (OCC-7274) GI (GI-13818) - aplastic - bingo test account - cant log in - Tech {Request #583658#}" Desired summary should be: "GI (GI-13818) - aplastic - bingo test account - cant log in - Tech {Request #583658#}"

Thanks in advanced, Shai

Comments (14)

  1. Fidel Castro Armario repo owner

    Hi Shai,

    Does the comment contain only the email's subject, or does the email's subject appears as the comment's first line, and the body of the email in the rest of the lines of the comment?

    Can you please provide an example of a whole comment?

    Regards,

    Fidel

  2. Shai Dahan Account Deactivated reporter

    Hello Fidel,

    It just a standard reply In this example this was their reply: ==========================

    Subject: RE: [GCI Jira] (OCC-7274) GI (GI-13818) - aplastic - bingo test account - cant log in - Tech {Request #583658#} Hello, We have checked the account and found one stuck game on BOS side which we have closed as it could have been preventing the account to log in. It is also possible that the issue occurs due to Flash being outdated, please update the flash on the computer and kindly retry to login. We did not detect any restrictions for the account. If the issue persists please let us know. As this is a test account would it be possible to provide us the login credentials so we could try and reproduce this on our side if the above steps did not solve the issue? Best regards, Martin Merisalu

    ==========================

    They receive an email from our Jira and they reply with the own ticket number at the end of the subject line. It always like that and we would like to change our subject line in a way that the number of their ticket will show at the end: "Original summary + {Request #?#}" (without the plus obviously)

    Thanks, Shai

  3. Fidel Castro Armario repo owner

    Hi Shai,

    You can use "Copy a parsed text to a field" post-function with the following configuration:

    conf-1.png

    Text to be parsed is:

    %{00000} + " " + replaceFirst(replaceFirst(%{00109}, "\\Q" + replaceFirst(%{00109}, "^.*\\{Request.*\\}", "") + "\\E", ""), "\\Q" + replaceFirst(replaceFirst(%{00109}, "\\Q" + replaceFirst(%{00109}, "^.*\\{Request.*\\}", "") + "\\E", ""), "\\{Request.*\\}$", "") + "\\E", "")
    

    Note that:

    • %{00000} is field code for "Summary".
    • %{00109} is field code for "Last comment".
  4. Shai Dahan Account Deactivated reporter

    Thanks Fidel,

    How do I match it so it will not action it over and over again? The same as you did with the previous ticket that you helped me with

    Thanks, Shai

  5. Fidel Castro Armario repo owner

    Just use the following text to be parsed:

    %{00000} + (matches(%{00000}, ".*\\{Request.*\\}.*") ? "" : (" " + replaceFirst(replaceFirst(%{00109}, "\\Q" + replaceFirst(%{00109}, "^.*\\{Request.*\\}", "") + "\\E", ""), "\\Q" + replaceFirst(replaceFirst(%{00109}, "\\Q" + replaceFirst(%{00109}, "^.*\\{Request.*\\}", "") + "\\E", ""), "\\{Request.*\\}$", "") + "\\E", "")))
    
  6. Shai Dahan Account Deactivated reporter

    Thank you Fidel, everything works as a charm :)

    If I want to copy only the number without the {Request ##} to an empty custom field i.e: {Request #584416#} only copy 584416 Should I use the same method (Copy a parsed text to a field)? I have a field called "Resolver Reference" which I want to copy the number into (i.e. 584416) Can I use the similar code?

  7. Fidel Castro Armario repo owner

    Just use the following text to be parsed:

    replaceFirst(replaceFirst(%{00109}, "\\Q" + replaceFirst(%{00109}, "^.*\\{Request\\s*#\\d+(?=#\\})", "") + "\\E", ""), "\\Q" + replaceFirst(replaceFirst(%{00109}, "\\Q" + replaceFirst(%{00109}, "^.*\\{Request\\s*#\\d+(?=#\\})", "") + "\\E", ""), "\\d+$", "") + "\\E", "")
    

    You gave me an idea. I will try to provide a new tool in a future version of the plugin, in order to parse fields for extracting tokens without needing to be a Regular Expression Jedi :-)

  8. Shai Dahan Account Deactivated reporter

    This is really hard to figure how to use the Regular Expression and it will be a great idea to add it to your add-on, which I find extremely useful. Thanks that has work wonderfully as always Now how do I match the value so it won't repeat the action again after the value has been copied? The same as you done previously i.e: %{00000} + (matches(%{00000}, ".\{Request.\}.*") ?

  9. Fidel Castro Armario repo owner

    In this case the value written into "Resolver Reference" is always the same, so you don't have to do nothing. JIRA doesn't log in the issue history any change for the custom field.

    Anyway, for efficiency you can use the following parsed text:

    %{13000} != null ? %{13000} : (replaceFirst(replaceFirst(%{00109}, "\\Q" + replaceFirst(%{00109}, "^.*\\{Request\\s*#\\d+(?=#\\})", "") + "\\E", ""), "\\Q" + replaceFirst(replaceFirst(%{00109}, "\\Q" + replaceFirst(%{00109}, "^.*\\{Request\\s*#\\d+(?=#\\})", "") + "\\E", ""), "\\d+$", "") + "\\E", ""))
    

    Note that %{13000} is field code for "Resolver Reference" in my JIRA instance. You have to replace that field code with the one in your particular JIRA instance.

  10. Shai Dahan Account Deactivated reporter

    Hello Fidel,

    Thank you for letting me know about the new feature and I'm sure it will be beneficial. I would rather though, wait for the official version before testing it as I want this need to be tested on production.

    Thanks again, Shai Dahan

  11. Shai Dahan Account Deactivated reporter

    Hello Fidel,

    I've updated you add-on and it looks very promising :) I'll you know how it goes.

    Shai

  12. Log in to comment