0

Below is my current code. It connects successfully to the organization. How can I fetch the results of a query in Azure like they have here? I know this was solved but there isn't an explanation and there's quite a big gap on what they're doing.

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
from azure.devops.v5_1.work_item_tracking.models import Wiql

personal_access_token = 'xxx'
organization_url = 'zzz'

# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)

wit_client = connection.clients.get_work_item_tracking_client()

results = wit_client.query_by_id("my query ID here")

P.S. Please don't link me to the github or documentation. I've looked at both extensively for days and it hasn't helped.

Edit: I've added the results line that successfully gets the query. However, it returns a WorkItemQueryResult class which is not exactly what is needed. I need a way to view the column and results of the query for that column.

1 Answers1

0

So I've figured this out in probably the most inefficient way possible, but hope it helps someone else and they find a way to improve it.

The issue with the WorkItemQueryResult class stored in variable "result" is that it doesn't allow the contents of the work item to be shown.

So the goal is to be able to use the get_work_item method that requires the id field, which you can get (in a rather roundabout way) through item.target.id from results' work_item_relations. The code below is added on.

for item in results.work_item_relations:
   id = item.target.id
   work_item = wit_client.get_work_item(id)
   fields = work_item.fields

This gets the id from every work item in your result class and then grants access to the fields of that work item, which you can access by fields.get("System.Title"), etc.