Order by a custom field

Description
AlexK
Posts: 2
Joined: Tue Mar 23, 2010 3:15 pm

Order by a custom field

Postby AlexK » Mon May 10, 2010 8:30 am

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 :-(

robertneher
Posts: 47
Joined: Sat Jan 22, 2005 10:56 am
Location: Stuttgart
Contact:

Re: Order by a custom field

Postby robertneher » Mon May 10, 2010 4:33 pm

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
Robert Neher, Polarion Software GmbH

ewiebe
Posts: 11
Joined: Fri Feb 26, 2010 3:05 pm

Re: Order by a custom field

Postby ewiebe » Mon May 31, 2010 12:12 pm

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?

robertneher
Posts: 47
Joined: Sat Jan 22, 2005 10:56 am
Location: Stuttgart
Contact:

Re: Order by a custom field

Postby robertneher » Mon May 31, 2010 1:00 pm

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...
Robert Neher, Polarion Software GmbH

ewiebe
Posts: 11
Joined: Fri Feb 26, 2010 3:05 pm

Re: Order by a custom field

Postby ewiebe » Mon May 31, 2010 1:20 pm

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

ewiebe
Posts: 11
Joined: Fri Feb 26, 2010 3:05 pm

Re: Order by a custom field

Postby ewiebe » Mon May 31, 2010 1:55 pm

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?

engeleb
Posts: 199
Joined: Wed Aug 09, 2006 10:55 am

Re: Order by a custom field

Postby engeleb » Wed Jun 02, 2010 10:19 am

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

ChernikovaEkaterina
Posts: 15
Joined: Mon Dec 07, 2009 9:08 pm

Re: Order by a custom field

Postby ChernikovaEkaterina » Wed Jun 02, 2010 5:42 pm

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

AlexK
Posts: 2
Joined: Tue Mar 23, 2010 3:15 pm

Re: Order by a custom field

Postby AlexK » Tue Jul 13, 2010 7:16 am

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.


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: Google [Bot], KellyHOm and 10 guests