Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to query work items once and get desired fields #496

Open
gp-bma opened this issue Apr 16, 2024 · 1 comment
Open

How to query work items once and get desired fields #496

gp-bma opened this issue Apr 16, 2024 · 1 comment

Comments

@gp-bma
Copy link

gp-bma commented Apr 16, 2024

Hi There, I tried to use the following codes to execute my query with wiql. However, it depends on two times api calls, one is query_by_wiql and the other is get_work_items. In the first method, it will get all the ids (but no other fields), in the later one, it will get work items based on the ids returned in the first method. My question is that is there a way to directly query and get my desired fields in just one call?

credentials = BasicAuthentication('', api_token)
connection = Connection(base_url=server, creds=credentials)
client = connection.clients.get_work_item_tracking_client()
wiql = Wiql(query=query)
wiql_results = client.query_by_wiql(wiql, top=100).work_items
if wiql_results:
    ids = [str(res.id) for res in wiql_results]
    work_items = client.get_work_items(ids, fields=fields)
@typorian
Copy link

typorian commented Apr 24, 2024

As you can see here, as you are requesting a WorkItemReference Object with your query_by_wiql (https://github.com/microsoft/azure-devops-python-api/blob/dev/azure-devops/azure/devops/v7_1/work_item_tracking/models.py#L1494), this object only has the ID and URL as attributes, so you do indeed need another query to get the additional properties, like you showed in your example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants