How to transition first sub-task of the parent issue?

Issue #105 resolved
Andrey Kiyanovsky created an issue

Hi!

Could you please advise how I can transit only first sub-task on parent issue transition.

Thank you in advance.

Comments (43)

  1. Fidel Castro Armario repo owner

    Hi Andrey,

    It will require JIRA Workflow Toolbox 2.1.28 (currently the most recent version) or higher. It can be done using 3 post-functions:

    1.- "Copy a parsed text to a field" post-function to write the name of a transition into virtual field "Ephemeral string 1" virtual field. In this example I use transition "Start Progress":

    conf-1.png

    2.- "Copy a parsed text to a field" post-function to write the issue key of first subtask order by a certain field into virtual field "Ephemeral string 2". In this example I order subtasks by creation date-time in ascending order:

    conf-2.png

    Notice that:

    • Text to be parsed is: toString(first(sort(subtasks(), {00009}, ASC)))
    • {00009} is code for numeric value of field "Date and time of creation".
    • We are using advanced parsing mode.

    3.- "Write field on issues returned by JQL query" post-function for copying the name of the transition in "Ephemeral field 1" into virtual field "Execute transition" of issue whose key is in "Ephemeral field 2":

    conf-3.png

    Notice that:

    • %{00062} is field code for "Ephemeral string 2".
    • JQL query used is: issuekey in ("%{00062}")

    #Once transition is configured, it will look like this:#

    conf-4.png

  2. Andrey Kiyanovsky reporter

    Hi Fidel!

    Thank you very much for your quick response. I need first subtask not by date, but by its position in subtasks list. As far as subtasks can be moved within a parent issue, I need topmost subtask in the list.

    Thank you in advance.

  3. Fidel Castro Armario repo owner

    In that case use parsed text toString(first(subtasks())) in post-function 2 instead of toString(first(sort(subtasks(), {00009}, ASC))).

  4. Andrey Kiyanovsky reporter

    Fidel, could you please advise how to transition next subtasks from previous subtask transition? I understand, that the scheme is the same as in the example above, but I can't create an appropriate expression.

  5. Fidel Castro Armario repo owner
    • changed status to open

    Do you need to transition the rest of issues at once, or one by one in different transition executions?

  6. Andrey Kiyanovsky reporter

    One by one. So when I resolve subtask I need to do Open -> To Do transition for the next subtask.

  7. Fidel Castro Armario repo owner

    Use parsed text toString(first(filterByStatus(subtasks(), "Open"))) in post-function 2.

  8. Andrey Kiyanovsky reporter

    Fidel, can we select not the first subtasks from the Open subtasks, but the next after current subtask if it is open? Because this is not the same.

  9. Fidel Castro Armario repo owner

    In relation to your former question, try the following parsed text in post-function 2:

    toString(first(filterByStatus(subtasks(), "Open")) INTERSECT first(subtasks() EXCEPT filterByStatus(subtasks(), "Resolved, Closed")))

  10. Andrey Kiyanovsky reporter

    Fidel, this toString(first(filterByStatus(subtasks(), "Open")) INTERSECT first(subtasks() EXCEPT filterByStatus(subtasks(), "Resolved, Closed"))) doesn't work. I think because there is no next subtask. If we were able to get the current subtask position in the subtasks() list, we will be able to get the next subtask in the subtasks() list, but I didn't find how to get a position of an element in the list. I try to use post-function "Write field on linked issues or subtasks", because it has "Next subtask" link, but can't handle the right options. Is there a function to display the string for debugging purposes?

  11. Andrey Kiyanovsky reporter

    I' doing the following:

    The following text parsed in basic mode will be copied to Parent's Ephemeral string 1: To Do

    Move up Move down Edit Delete Value of field Ephemeral string 1 in current issue will be copied to field Issue status (delayed writing) in linked issues or subtasks filtering by: Inward issue link types: none Outward issue link types: Next Sub-Task. Subtasks won't be written. Sibling subtasks won't be written. Issue types: any Statuses: Open. Linked issues or subtasks must belong to same project as current issue.

    It doesn't work.

  12. Fidel Castro Armario repo owner

    According to your description, "Write field on linked issues or subtasks" should work.

    Some questions:

    • Which issue is executing the transition where you use post-function "Write field on linked issues or subtasks", the parent issue or a subtask? When you said "...the next after current subtask if it is open...", it makes me think that you are executing the post-functions in sub-task's workflow, not in parent issue's workflow.

    • Is there always an issue link "Next Sub-task" for the parent issue to the sub-task you want to move? In affirmative case, also in the case of the first subtask?

    • Can we have an Skype screen-share in order to see all the problem in direct?

  13. Andrey Kiyanovsky reporter

    I'm using post-function in subtask Resolve transition. I want to transition next sub-task from Open to To Do status. I was thinking that "Next Sub-Sask" link in automatic link between subtasks within same parent issue. It would be helpful to have a Skype call, please ping me when you are available, my Skype Account andrey.kiyanovsky

  14. Fidel Castro Armario repo owner

    After our Skype meeting I have found that there was a misunderstanding about where the solution is going to be executed. The solution above described is thought to be executed in parent issue's workflow, but you need it to be executed in subtask's workflow, i.e., each subtasks moves its next open sibling issue when is resolved.

    The only change to be done is in the expression to be parsed in 2th post-function. Simply use the following expression:

    toString(first(filterByStatus(subtasks(%{00041}), "Open")) INTERSECT first(subtasks(%{00041}) EXCEPT (filterByStatus(subtasks(%{00041}), "Resolved, Closed") UNION issueKeysToIssueList(%{00015}))))

    Once configured, your "Resolve Issue" transition in subtask's workflow will look like this:

    conf-5.png

  15. Andrey Kiyanovsky reporter

    This comment gives the following results: TCC-8 / TCC-8 / / TCC-8 where TCC-8 - is current subtask. The next sub-task is TCC-10

  16. Fidel Castro Armario repo owner

    I didn't take into account that you could be resolving directly from "Open" status. Use the following expression to cope with that eventuality:

    toString(first(filterByStatus(subtasks(%{00041}), "Open") EXCEPT issueKeysToIssueList(%{00015})) INTERSECT first(subtasks(%{00041}) EXCEPT (filterByStatus(subtasks(%{00041}), "Resolved, Closed") UNION issueKeysToIssueList(%{00015}))))

  17. Andrey Kiyanovsky reporter
    Hi, Fidel! Now it works, but not how I was expecting.  Because I need to transition next task, not the first task. Example:
    
    *Example 1* 
    Initial: 
    1 subtask = In Progress
    2 subtask = In Progress -> Resolved
    3 subtask = Open
    
    Result:
    1 subtask = In Progress
    2 subtask = Resolved
    3 subtask = Open
    
    Expected:
    1 subtask = In Progress
    2 subtask = Resolved
    3 subtask = To Do
    
    *Example 2*
    Initial:
    1 subtask = Open
    2 subtask = In Progress -> Resolved
    3 subtask = Open
    
    Result:
    1 subtask = To Do
    2 subtask = Resolved
    3 subtask = Open
    
    Expected:
    1 subtask = Open
    2 subtask = Resolved
    3 subtask = To Do
    
    Is there any chance to transition only *next* subtask(s)? We need to have one subtask after the current subtask in To Do or In Progress status. So the ideal algorithm will be the following:
    n = 1
    :start
    If the subtask(current+n) NOT EXIST goto exit endif
    if the subtask(current+n).status = To Do or In Progress then goto exit endif
    if the subtask(current+n).status = Open then subtask(current+n).status = To Do; goto exit endif
    n=n+1
    goto start
    :exit
    
    
    The less ideal algrorithm will be the following:
    If the subtask(current+1) exist and status = Open then subtask(current+n).status = To Do
    
    I'm very thankful for your help.
    
  18. Fidel Castro Armario repo owner
    • changed status to open

    Andrey, now I see clearly all your requisites and with current version of the plugin It's not possible to implement them.

    Tomorrow, I expect to have a new beta version of the plugin with 2 additional functions for list management (findElement() and subList()) that will make it possible to implement all your requirements.

    Now, I open the issue again.

  19. Fidel Castro Armario repo owner

    I have made available version 2.1.29_beta_3 which implements 2 new parsing functions: indeOf(element, list) and sublist(list, indexFrom, indexTo).

    Using this new version of the plugin, you can implement your requisites using the following expression at post-function 2:

    toString(filterByStatus(first(sublist(subtasks(%{00041}), indexOf(%{00015}, subtasks(%{00041})), count(subtasks(%{00041}))) EXCEPT issueKeysToIssueList(%{00015}) EXCEPT filterByStatus(sublist(subtasks(%{00041}), indexOf(%{00015}, subtasks(%{00041})), count(subtasks(%{00041}))) EXCEPT issueKeysToIssueList(%{00015}), "Resolved, Closed")), "To Do, Open"))

    Take into accout that you should replace strings "Resolved, Closed" and "To Do, Open" with the particular statuses you use in your workflow.

  20. Andrey Kiyanovsky reporter

    Hi Fidel, I got you! Thank you very much for help!

    I have a question regarding "Write field on JQL issue" - if I use JQL request issuekey in ("%{ephemeral string}"). If %{ephemeral string} is empty or contain one issue key, it's work. But if it has two or more keys, it doesn't work. In JIRA issue navigator request issuekey in ("tcc-144, tcc-168") doesn't work too. If I use issukey in (%{ephemeral string}) - without quotes, it fails with the empty ephemeral string. Please, advise.

  21. Fidel Castro Armario repo owner

    The expression I provide you at 2th post-function always return 1 or 0 issue keys, so you should use issuekey in ("%{ephemeral string}") as JQL query at 3er post-function.

    If I'm not wrong, you shouldn't have any problems with that solution.

  22. Andrey Kiyanovsky reporter

    Fidel, I use JQL query in other workflow, where I can have any number of issue keys.

  23. Fidel Castro Armario repo owner

    You can preprocess the Ephemeral String virtual field containing issue keys with "Set a field as a function of other fields" post-function, in order to set it with "" value in case it doesn't contain issue keys. It can be done as I show you in the following screenshot:

    Captura de pantalla 2015-03-07 a las 22.47.39.png

    Setting rule used is: (\s*)""

    After that, you can use the preprocessed Ephemeral String virtual field in "Write field on JQL issue" in JQL query without doble quotes, i.e., issuekey in (%{ephemeral string})

  24. Fidel Castro Armario repo owner

    There is a more compact solution in case you are using an expression at "Copy a parsed text to a field" post-function for selecting issues, and getting a comma separated list of issue keys.

    The solution consists in using conditional operator ? : (you can see how it works at parser documentation) for getting a "" value in the case expression is returning zero issue keys. To do it you should write something like:

    expression = "" ? "\"\"" : expression

    In the following example, I want to get into Ephemeral string 1 a comma separated list with subtask's issue keys, or in case parent issue doesn't have any subtasks, a "" string. We would use the following configuration at "Copy a parsed text to a field" post-function:

    conf-1.png

    Used expression is: toString(subtasks()) = "" ? "\"\"" : toString(subtasks())

  25. Andrey Kiyanovsky reporter

    Fidel, one more question. May be this is a bug.

    I need to check status of all linked with "relates to" Bugs and Stories - they have to be resolved. I create Validation on linked issue: Validation.png

    In this issue (2 resolved bugs and no Stories): Story.png

    I get validation fails:

    Result.png

    If I change Validation to the following, all come without errors:

    2015-03-08_003919.png

    But in the documentation said, that "Linked issues in unselected issue types will be ignored", but it is not so. Please, advise.

  26. Fidel Castro Armario repo owner

    That is not a bug. You should check the following parameters:

    • Allow unselected issue link types:, in order to not apply validation requirements to other issue link types different from selected ones, i.e., if there are issues linked with other issue link types, we will not require them conditions on issue types, statuses, project belonging, and max-min numbers.
    • Allow unselected issue types:, ir order to not apply rest of validation requirements, even if they are linked with selected issue link types, i.e., issue types different from "Bug" and "Story" may be linked with "relates to" and be in "Open", "Reopen" or "In Progress" statuses.
  27. Fidel Castro Armario repo owner

    Please, for questions different from original one, create another issue. Thanks.

  28. Andrey Kiyanovsky reporter

    Fidel, I just have tried your new function and get the error: toString(filterByStatus(first(sublist(subtasks(%{00041}), indexOf(%{00015}, subtasks(%{00041})), count(subtasks(%{00041}))) EXCEPT issueKeysToIssueList(%{00015}) EXCEPT filterByStatus(sublist(subtasks(%{00041}), indexOf(%{00015}, subtasks(%{00041})), count(subtasks(%{00041}))) EXCEPT issueKeysToIssueList(%{00015}), "Resolved, Closed")), "Open")) :: LEXICAL ERROR : Lexical error at line 1, column 34. Encountered: "l" (108), after : "sub"

    Please advise. Version 2.1.28.

  29. Fidel Castro Armario repo owner

    I have added the new functions in a beta version 2.1.29_beta_4. Version 2.1.28 is most the recent released stable version, but it doesn't include the new features.

    In order to install the new version, you have to navigate to Administration -> Add-ons -> Manage Add-ons, and then:

    1. Uninstall version 2.1.28.
    2. Install version 2.1.29_beta_4 by uploading the .jar file (clicking on "Upload add-non").
  30. Log in to comment