Page 1 of 1

Order by a custom field

Posted: Mon May 10, 2010 8:30 am
by AlexK
Hello,

is it possible to order a work items query by a custom field?

Like this

Code: Select all

$workItems = $trackerService.queryWorkItems("$projectId", "customField.field-application")


I tried this and some other modifications but it won't work :-(

Re: Order by a custom field

Posted: Mon May 10, 2010 4:33 pm
by robertneher
Hi Alex,

a brief look into the examples delivered with Polarion SDK (to be found in .../polarion/polarion/SDK/examples) shows me something which would probably match your request

String[] fields = { "resolution", "id" };
WorkItem[] linkedWIs = trackerService.queryWorkItems(query, null, fields);

if ((linkedWIs == null) || (linkedWIs.length == 0)) {
String err = "No valid IDs of WorkItem found.";
logError(err);
return false;
}

ADDED: If you put a tilde "~" as prefix to the field ID, like "~updated", you will the list in descending order.

Does this help?

Best Regards,
Robert

Re: Order by a custom field

Posted: Mon May 31, 2010 12:12 pm
by ewiebe
What is about cusom fields.
The fields you have entered are standard fields (e.g. "id"), but if I have custom fields in:
ProjectName\.polarion\tracker\fields\feature-custom-fields.xml

there are e.g.
<?xml version="1.0" encoding="UTF-8"?>
<fields>
<field id="oemID" type="string" name="OEM ID" description="The ID the customer has for this Issue."/>
</fields>

Question: How to query WorkItems with these custom fields?

Re: Order by a custom field

Posted: Mon May 31, 2010 1:00 pm
by robertneher
This is pretty straight forward.
Just use the Query Builder and you can see how the query should look like.
In your example it could oemID:serchString

Hope that helps...

Re: Order by a custom field

Posted: Mon May 31, 2010 1:20 pm
by ewiebe
It is little different:
(I am programming in C#)
1. get all available workitems with default fields (I use type, id, title, description, status, timePoint, author, severity)
by calling m_trackerService.queryWorkItems(qu, sortString, fieldsarray)
qu = "project.id:" + projectID + " AND ExternalIssue:True AND IssueSource:Customer";

2. I get a list of workitems

3. If I want to see special (custom Fields):
string[] keys = m_trackerService.getDefinedCustomFieldKeys(projectID, "fact");
With this I get all available custom fields for FACT WI

4. CustomField cf = m_trackerService.getCustomField(wi.uri, "oemID");
gives me the value of the custom field

That is the solution

Re: Order by a custom field

Posted: Mon May 31, 2010 1:55 pm
by ewiebe
But an other problem:

when I have a shortcut defined which is used inside Polarion:
<shortcut columns="id:183,project:110,title:169,status:56,assignee:90,timePoint:150,ExternalIssue:90,IssueSource:90,oemModule:90,oemID:90,oemObjectType:90,oemStatus:90" filter_all_levels="yes" icon="/polarion/ria/images/details/table.gif" name="LH (Lastenheft)" pagePath="workitems" query="ExternalIssue:True AND IssueSource:Customer" scope="project/BR_CALC123" sorting="~status,id" table_mode="tree" tree_depth="6"/>

Question:
How to make a query over web services, that I will get the same elements IN SAME ORDER as in Polarion?

If I do this query with:
WorkItem[] items = m_trackerService.queryWorkItems(qu, sortString, fieldsarray); //was "ID" as sortstring
where:
qu = "project.id:BR_CALC123 AND ExternalIssue:True AND IssueSource:Customer"
sortString = "~status,id"
fieldsarray: type, id, title...

I get the same count of WIs but in different sorting order. What is wrong?

Re: Order by a custom field

Posted: Wed Jun 02, 2010 10:19 am
by engeleb
Hi,

Most likely the shortcut shows a different soring because it shows a tree of work items.
If the web services returns the work items ordered by status (reverse) as primary and id as secondary sorting criteria the result is as expected.

If you need the sorting according to the tree you will have to do that by analyzing the links (linkedWorkItems field) in your code.

Best Regards,
Benjamin

Re: Order by a custom field

Posted: Wed Jun 02, 2010 5:42 pm
by ChernikovaEkaterina
Hi,
there are two problems:
1) Polarion user interface slightly modifies the sort string: it checks whether there are keys 'id' and 'created' and if not, it adds them in descending order. Thus sort string "~status, id" in shortcut is modified to "~status, id, ~created". ITrackerService or ITrackerWebService use the sort string as is.
2) You specified table_mode="tree" in the shortcut but in that case resulting workitems are treated as nodes of a tree and could be completely rearranged with respect to some parent-child hierarchy. You have to use table_mode="flat" if you want to keep the specified sort order.


Best Regards,
Ekaterina Chernikova
Support Polarion Software

Re: Order by a custom field

Posted: Tue Jul 13, 2010 7:16 am
by AlexK
Sorry i found the solution and forgot to answer here.

Code: Select all

$workItems = $trackerService.queryWorkItems("$projectId", "customFieldId")


This worked for me.

Thanks a lot for helping.