简体   繁体   English

TFS-如何使用Java SDK获取工作项数据

[英]TFS- how to get workitem data using java sdk

Can I get value of workitem fields, for example related to "Assigned to" field, from Workitem object? 我可以从Workitem对象获取工作项字段的值,例如与“分配给”字段相关的值吗? I use TFS SDK for Java. 我使用Java的TFS SDK。

I am able to view work items of TFS using below code: 我可以使用以下代码查看TFS的工作项:

public static  TFSTeamProjectCollection connectToTFS() throws URIException, SQLException
{
    TFSTeamProjectCollection tpc = null;
    Credentials credentials;

    credentials = new UsernamePasswordCredentials("username,"password");
    tpc = new TFSTeamProjectCollection(URIUtils.newURI("http://0.0.0.127:8080/tfs/DefaultCollection"), credentials);
    return tpc;
}


// get connection using above method
TFSTeamProjectCollection tpc=connectToTFS();
WorkItemClient workItemClient = tpc.getWorkItemClient();
// Define the WIQL query.          
String wiqlQuery = "Select ID, Title from WorkItems where (State = 'Active') order by Title";

// Run the query and get the results.          
WorkItemCollection workItems = workItemClient.query(wiqlQuery); 
final int maxToPrint = 20;

for (int i = 0; i < workItems.size(); i++)          
{ 
    if (i >= maxToPrint)              
    { 
        System.out.println("[...]");                  
        break; 
    } 
    WorkItem workItem = workItems.getWorkItem(i); 

    System.out.println(workItem.getID());
    System.out.println(workItem.getTitle()); 
    System.out.println(workItem.getProject().getName()); 
    System.out.println(workItem.getClient().getUserDisplayName());        
} 

Using below statements we can get exactly assign_to field value. 使用下面的语句,我们可以确切地获取assign_to字段值。

  for (int i = 0; i < workItems.size(); i++)          
    { 

        WorkItem workItem = workItems.getWorkItem(i);  

        workItem.syncToLatest();
            System.out.println("task  assigned to "+ workItem.getFields().getField("Assigned to").getValue()+" Task title is   "+workItem.getFields().getField("title").getOriginalValue());


    } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM