Page 1 of 1

Get real starting date of an item

Posted: Fri Apr 06, 2018 11:06 am
by victorien
Hello, I am having a little trouble getting starting date of some items.
I am trying to do this in a velocity script live report page.
I made a custom field called start date but it is not always filled.

I would like to know if it is possible to somehow get the real starting date value of an item (the date when the item status went in progress). Just like we can see if we click "history" of the item.

I would then like to set the result as string (ex 2018-12-02).

Re: Get real starting date of an item

Posted: Mon Apr 09, 2018 10:38 am
by Jürgen
Why not use IWorkItem.getCreated() ?

Re: Get real starting date of an item

Posted: Mon Apr 09, 2018 12:38 pm
by ALMighty
Jürgen wrote:Why not use IWorkItem.getCreated() ?


I think it is not that easy because the thread creator does not want to know when a work item
For that purpose one must get the history of a work item and traverse through it.

victorien wrote:I would like to know if it is possible to somehow get the real starting date value of an item (the date when the item status went in progress). Just like we can see if we click "history" of the item.


Yes you can, with the DiffManager. You can get the Diffmanager withe the following code line:

Code: Select all

#set( $diffman = $trackerService.getDataManager().getDiffManager() )


And then you can use the generateHistory method, the first parameter is the work item (not the work item ID, the whol work item object as you get it e.g. from queryWorkItems) and the second, the list of ignored fields, can be null I guess.

The method generateHistory gives you an array of IChange objects, which you have to traverse in a foreach loop. Each change object, as far as I see it however, can consist of multiple IFieldDiff objects which you can get as an array when invoking getDiffs on a IChange object.

In each FieldDiff object of the array you can get the field that was changed, here you have to check if you have the status field detected. When invoking [url]=https://almdemo.polarion.com/polarion/sdk/doc/javadoc/com/polarion/platform/persistence/diff/IFieldDiff.html#getAfter--getAfter[/url], I think you have to check it that way in order to see if the work item was set to in progress:

Code: Select all

#if($fieldDiffSelectedInLoop.getAfter().getId() == "in_progress")

Or, If I am wrong and String comparison does not work that way in Velocity, do it this way:

Code: Select all

#if($fieldDiffSelectedInLoop.getAfter().getId().compareTo("in_progress") == 0 )


You need to use getId() in this case because what you get is not just a String but an IStatusOpt object.

Re: Get real starting date of an item

Posted: Mon Apr 09, 2018 1:31 pm
by SaoBit
To get a larger table with these dates is a performance-killer when using the diffmanager.
It would be better to change the workflow to set your custom field to the correct date.
See Help - Search for "ChangeField".

When there are a lot of Work Items that don't have the field filled properly, try to create a Classic Wiki Page to get the date once and fill the field.

Re: Get real starting date of an item

Posted: Thu Apr 12, 2018 10:21 am
by victorien
Thanks for your replies, I will indeed use the workflow instead, but I will keep diffmanager in mind, it might be useful for some cases.
Thanks a lot !