Calculating Priority from linked Item does not work

Description
Oliver.Meyer
Posts: 6
Joined: Wed Jun 10, 2015 4:11 pm

Calculating Priority from linked Item does not work

Postby Oliver.Meyer » Thu Mar 29, 2018 7:55 am

Hi,

My problem:
I try to calculate the priority of a task from the priority of the requirement it implements, but I fail.

What I have:
I have work items of type requirements.
I have work items of type task.
I create relations task -implements-> requirements (Usualy multiple tasks implement one requirment).
We actively maintain and manage the priority of requirements.

I want to order tasks in accordance to the priority of the requirement they implement.

What I did
I marked the implements relation to be parent.
I created a custom field "derived priority" in task of type "float".
I created a calculation that calculated the "derived priority" to be the average of the parent "priority" (I like to see max, but did average for no reason).
I did run the Calculate fields job, which returned OK after a few seconds.

What I tried
I created another custom field "child Priority" in task of type float and created another calculation to set it as maximumg of the childs priority fields, because I am unsure about who is parent and who is child. I found "the child points to its parent" in the documentation, so I believe that task is the child of requirement. Can someone confirm that?

Questions:
  • What do I have to do to make it work?
  • What am I doing wrong?
  • Why is this not working as expected?

I would be happy to attach configuration xml files if required.

Thanks for any pointers,
Oliver

ALMighty
Posts: 80
Joined: Wed Apr 27, 2016 10:34 am
Location: Austria

Re: Calculating Priority from linked Item does not work

Postby ALMighty » Thu Mar 29, 2018 12:25 pm

Oliver.Meyer wrote:I created a calculation that calculated the "derived priority" to be the average of the parent "priority" (I like to see max, but did average for no reason).
[...]
What I tried
I found "the child points to its parent" in the documentation, so I believe that task is the child of requirement. Can someone confirm that?



Yes, your assumption concerning the child role is a good hint. I remember those occasions when I had to implement a structure with calculated fields and it sometimes drove me nuts because it isn't obvious at all which side of the linking is parent or child and if you got it wrong the calculation does not work of course. :evil: The fact that Work Item A is indicated on top or above linked Work Item B is alas no indicator.

So have again a look in /administration/workitems/enumerations of your project and check the workitem-link-role-enum.xml to see in which relationship your tasks and requirements are. :wink:

Furthermore, you can also determine that through a PostgreSQL query that shows you all the linked items from both directions, so parent and child. This allows you to see if your task and requirements in question are either parent or child in their relationship:

Code: Select all

SELECT
baseQuery.fk_p_workitem, baseQuery.fk_uri_p_workitem,
parentItemQuery.c_id AS parentWorkItemID, parentItemQuery.c_type AS parentWorkItemType, -- parent item fields
baseQuery.c_role, baseQuery.fk_workitem, baseQuery.fk_uri_workitem,
childItemsQuery.c_id AS childWorkItemID, childItemsQuery.c_type AS childWorkItemType, -- child item fields
baseQuery.c_revision, baseQuery.c_suspect
FROM polarion.struct_workitem_linkedworkitems baseQuery
JOIN (SELECT c_pk, c_id, c_type FROM polarion.workitem -- fetches the fields for the parent item
) parentItemQuery
ON baseQuery.fk_p_workitem = parentItemQuery.c_pk
JOIN (SELECT c_pk, c_id, c_type FROM polarion.workitem -- fetches the fields for the child item
) childItemsQuery
ON baseQuery.fk_workitem = childItemsQuery.c_pk
ORDER BY parentItemQuery.c_id


For executing such a query you (or your system administrator) must establish access to the Postgre SQL database of your Polarion installation (both pages I have linked are temporaily unavailable but should be online again soon). Furthermore you need a client in order to do the query, I can recommend pgAdmin III.
---------------------------------------------------------------------------------------------------
Playing a good game is never lame. :D
Image

Oliver.Meyer
Posts: 6
Joined: Wed Jun 10, 2015 4:11 pm

Re: Calculating Priority from linked Item does not work

Postby Oliver.Meyer » Thu Mar 29, 2018 1:33 pm

Thanks. I tried to work around the orientation issue of the relation, by adding another calculation that gets values from the child items instead of the parent. So, I expect one of those to receive values, but no :(

I attach the config files:

Am I doing something stupid, like priority is not float? priority is called priority.1?

ALMighty
Posts: 80
Joined: Wed Apr 27, 2016 10:34 am
Location: Austria

Re: Calculating Priority from linked Item does not work

Postby ALMighty » Thu Mar 29, 2018 2:34 pm

Oliver.Meyer wrote:Am I doing something stupid, like priority is not float? priority is called priority.1?


Now that you mentioned it, I have the concern that this might actaully be the case.
I also tried out what you did (in a calc-field setup that definitely worked before when using other fields)
in order to calculate an average based on the priority and so far nothing happened, although I actively changed values in the child items which actually triggered a calculation in almost all the cases I know. :(

Moreover I see the theory that priority cannot be used as a calculated field confirmed through the info that is indicated in the the calculated field menu of any work item type (see attached picture). :?
Attachments
calcFieldsDerived.PNG
An indicator that priority cannot be used as a calculated field.
calcFieldsDerived.PNG (21.36 KiB) Viewed 1799 times

Oliver.Meyer
Posts: 6
Joined: Wed Jun 10, 2015 4:11 pm

Re: Calculating Priority from linked Item does not work

Postby Oliver.Meyer » Thu Mar 29, 2018 3:06 pm

Thank you very much for the pointer!

I read that section before. My interpretation was and is, that priority cannot be used as calculated field. But, I should be able to use it as the source for calculating another user defined field "derivedPriority".

But: I could try to calculate something else instead of priority to gather more experience with calculated fields and then come back to priority. Or try to calculate the derivedPriority from the priority of the item itself. Further reducing the error space.

Oliver.Meyer
Posts: 6
Joined: Wed Jun 10, 2015 4:11 pm

Re: Calculating Priority from linked Item does not work

Postby Oliver.Meyer » Fri Mar 30, 2018 8:13 am

I think it cannot be done. The documentation is propably right (to some extend) and the UI is crap. Documentation says:
ScrShot-Help - Polarion ALM Platform - Mozilla Firefox-20180330095348.png
ScrShot-Help - Polarion ALM Platform - Mozilla Firefox-20180330095348.png (8.65 KiB) Viewed 1781 times

So no "getting values from Parents."

I did a test with two new fields on task, both float: value and calcvalue.
I then created two task workitems child and parent in relation child-implements->parent.

In the UI for calculated fields I am given the option to take value from Child field or Parent field. I tried both and it turns out, that Parent field actually means same items field :(
ScrShot-Calculated Fields Configuration _ Work Items _ PIDT - Mozilla Firefox-20180330094742.png
ScrShot-Calculated Fields Configuration _ Work Items _ PIDT - Mozilla Firefox-20180330094742.png (3.67 KiB) Viewed 1781 times

In the configuration shown, the calcValue of Parent becomes the same as the value of Child.
If I switch to Parent field the calcValue of Parent and Child update. The value is just copied over into the calcvalue field in each item.

Now I have to come up with another solution to my problem of sorting the tasks according to the requirement priorities....

ALMighty
Posts: 80
Joined: Wed Apr 27, 2016 10:34 am
Location: Austria

Re: Calculating Priority from linked Item does not work

Postby ALMighty » Tue Apr 03, 2018 11:35 am

Oliver.Meyer wrote:Now I have to come up with another solution to my problem of sorting the tasks according to the requirement priorities....


And perhaps I have one, by setting a function in the workflow table of your task.
The corresponding chapter in the Polarion help is here(search for the heading "Workflow Functions (Work Items)").

My solution consists of a javscript file that is executed in every work flow action of the task.
Here it is, I have not tested it but I have written it based on another JS file I executed that way,
so I guess it should work. COpy the following code and save it in a file that we call calcAveragePriority.js:

Code: Select all

var workitem = workflowContext.getTarget(); // here we get the task
var linked_items = workitem.getLinkedWorkItems(); // To be honest I do not know in which direction the linked items (parent of child only) are fetched here, you have to test it please

var requirementsPrioritySum = 0;
var linkedRequirementsCount = 0;
var averagePriority = 0;

for (i = 0; i < linked_items.length; i++)
{
   
   /* The type */
   if(linked_items[i].getType().id == "requirement")
   {
      dueDate_of_Parent = linked_items[i].getDueDate();
      linkedRequirementsCount++;
      requirementsPrioritySum = requirementsPrioritySum + linked_items[i].getPriority():
   } /* end of if */
         
} /* end of for loop */

/* calculating the average priority of the requirements that is then inserted in the priority field of the parent task */
averagePriority = (requirementsPrioritySum / linkedRequirementsCount);

workitem.setValue("priority", average );
/*
Or does setting the value work that way? I am not sure anymore
workitem.setPriority( average )
*/

workitem.save();

.
Note that this script does only run in the context of work item status transitions in Polarion.
You have to enter the workflow menu in the administration section of your Polarion project.
Pick any work item type and go to the "Actions" section of the workflow page of the item.
There you can enable a script function option. This will trigger a script every time the Action is executed.
Enter then as Parameters (the text in CAPITAL LETTERS) are the columns.

NAME | VALUE | ACTIONS
engine | javascript
script | calcAveragePriority.js

The file your_javascript.js is now then executed every time the specific work item Action (status transition) is executed and no Polarion extension is needed for that functionality.

NOTE: calcAveragePriority.js must be stored in the scripts folder of the Polarion installation (to C:\Polarion\scripts or the equivalent folder in Linux: /opt/polarion/scripts). Ask you System Administrator for getting access to these folders.
Basically, you can apply all methods on work items that are listed here (this is usually the reference for Velocity scripts):
https://almdemo.polarion.com/polarion/s ... kItem.html
---------------------------------------------------------------------------------------------------
Playing a good game is never lame. :D
Image


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 14 guests