first(fieldHistory(%{Assignee})) returns always zero

Issue #247 resolved
Andrey Kiyanovsky created an issue

It seems like fieldHistory returns comma separated string instead of String List, because the following expression works: first(toStringList(toString(fieldHistory(%{Assignee})),","))

Comments (13)

  1. Fidel Castro Armario repo owner

    Hi Andrey,

    There isn't any bug here. I explain each term of the expression:

    fieldHistory(%{00003})
    

    returns a string list.

    toString(fieldHistory(%{00003}))
    

    returns a string with a comma separated of values.

    toStringList(toString(fieldHistory(%{00003})),",")
    

    returns a string list again.

    You can use the following simpler and equivalent expression:

    first(fieldHistory(%{00003}))
    

    but since fieldHistory(%{00003}) might return an empty list, and first() applied to an empty list will throw and error, you should use the following expression:

    count(fieldHistory(%{00003})) > 0 ? first(fieldHistory(%{00003})) : ""
    

    Note that %{00003} is field code for Assignee.

  2. Andrey Kiyanovsky reporter

    Thanks a lot, Fidel! It was not evident from the documentation.

    Fidel, is there a way to get to know the latest assignee of the issue in some status? I really need this function, can't finish my auto-assign scheme without it.

  3. Andrey Kiyanovsky reporter

    Fidel, I have one more question regarding fieldHistory. It seems like it doesn't keep history for assigned from post-function.

    So in my case I want to assign issue:

    in To Do - first Assignee

    In QA - custom_field_Assigned_QA.value

    Here is the problem:

    1. Create an issue and assign it

    2. Transition to QA, issue auto-assigned to the field value

    3. Transition to To Do - fieldHistory(Assign) is empty, I can't assign back to First Assignee

    Please, advice how I can do this. I think it'd be better to keep all assignee in the fieldHistory, including first and all post-function assigned. Is it possible?

  4. Fidel Castro Armario repo owner

    Hi Andrey, which post-function are you using in transition 2 to assign issue to custom field value?

  5. Andrey Kiyanovsky reporter

    Fidel, for step 2 I use Set a field as a function of other fields Function, example. Highlighted row doesn't work, because it doesn't catch either first manual assignee or assignee from post-functions.

    I'd like to implement two algorithms.

    1. Assign issue to the very first assignee (no matter was it manual or auto) - can't do that because fieldHistory() doesn't catch both cases.
    2. Assign issue to the last assignee in the status - can't do that because there is no function to get to know the last assignee of a status.

    So I'd like to have the following. 1. fieldHistory() catch each and every assignee. 2. statusLastAssignee(status) - who was assigned, returns empty for "unassigned" or "user". Or some assignee/status historical function.

  6. Fidel Castro Armario repo owner

    I Andrey,

    In my test fieldHistory() is correctly retrieving assignees set by JIRA Workflow Toolbox post-functions. I show you my test configuration and result:

    Transition "Create Issue":

    Captura de pantalla 2016-02-22 a las 19.20.41.png

    Creating a test issue:

    Captura de pantalla 2016-02-22 a las 19.21.16.png

    Result obtained in issue Description:

    Captura de pantalla 2016-02-22 a las 19.21.37.png

    The result obtained are the first two assignees (newton and feynman), and the current assignee is not returned.

    In case you are working with "Create Issue" transition, it's very important that you move post-function "Creates the issue originally" to first position in execution order. Please, check it up.

  7. Andrey Kiyanovsky reporter

    Fidel. it seems like I found an error (in 2.2.6.1).

    1. This is an example of my assign step in every status.
    2. This is a debug function.
    3. This is the result after several transactions (the first assignment was manual, others - automatic via post-functions)

    Please pay attention at the comma in the beginning of the string. That is why my function doesn't work - it tries to assign an empty value. Please investigate.

    P.S. What about the last assignee in the status? Will it be possible to add this function?

  8. Andrey Kiyanovsky reporter

    It's strange that I cannot see a comma in your example and see at my example. Just checked - I get the same result (with comma) even for manual assignments only.

  9. Fidel Castro Armario repo owner

    That comma is due to an empty string (i.e., "") at first position in the string list, which is due to the issue being unassigned just after creation. In my case the issue is always assigned to a user.

    In the function documentation this behavior is explained in a general manner: Captura de pantalla 2016-02-22 a las 20.08.38.png

  10. Andrey Kiyanovsky reporter

    Got it, thank you, Fidel.

    Sorry to be persistent, what about "the last assignee in status function"?

  11. Fidel Castro Armario repo owner

    In relation to your second requirement, I have to work on it. I would like to design a more general solution, where it is possible to do any query on the issue history.

    I hope I can something more concrete soon.

    Meanwhile, isn't it possible to that you use a hidden custom field, that you would set using a post-function in each transition with origin in the status you want to register its last assignee? I think that this workaround should work for you, and is not too annoying to implement.

  12. Andrey Kiyanovsky reporter

    I believe more general solutions would be better )

    Thank you for the suggestion, will try to implement it.

  13. Log in to comment