Query.and.Update.WorkItems 1.0.3

dotnet add package Query.and.Update.WorkItems --version 1.0.3
NuGet\Install-Package Query.and.Update.WorkItems -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Query.and.Update.WorkItems" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Query.and.Update.WorkItems --version 1.0.3
#r "nuget: Query.and.Update.WorkItems, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Query.and.Update.WorkItems as a Cake Addin
#addin nuget:?package=Query.and.Update.WorkItems&version=1.0.3

// Install Query.and.Update.WorkItems as a Cake Tool
#tool nuget:?package=Query.and.Update.WorkItems&version=1.0.3

About

Helper class showcasing QueryByWiqlAsync and UpdateWorkItemAsync methods with explanation. With these two methods you should be able to get details on your WorkItems and update them. Utilizes PAT.

Runs with netcoreapp3.1, net5.0 and net6.0.

Example

using Azure.DevOps.Query.and.Update.WorkItems;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using System.Collections.Generic;

namespace ConsoleApplication
{
    internal class Program
    {
        static void Main()
        {
            string orgName = "name of your organization";
            string personalAccessToken = "your PAT";

            var queryExecutor = new QueryExecutor(orgName, personalAccessToken);

            IList<WorkItem> workItems;

            string query = "Select [ID] " +
                    "From WorkItems " +
                    "Where [State] = 'To Do' " +
                    "AND [System.TeamProject] = 'name of your project'";

            string[] fields = { "System.Id", "System.Title", "System.Description", "System.AssignedTo" };

            //workItems = await queryExecutor.QueryWorkItems(query, fields);
            workItems = queryExecutor.QueryWorkItems(query, fields).GetAwaiter().GetResult();


            foreach (WorkItem workItem in workItems)
            {
                string title = workItem.Fields["System.Title"].ToString();
                string assignedTo = workItem.Fields["System.AssignedTo"].GetType().GetProperty("DisplayName").GetValue(workItem.Fields["System.AssignedTo"], null).ToString();
            }

            //await queryExecutor.UpdateField(workItems[0], "System.Description", "This was already done");
            queryExecutor.UpdateField(workItems[0], "System.Description", "This was already done").GetAwaiter().GetResult();
        }
    }
}


Organization name and project

https://dev.azure.com/organization/project/

Personal access token

How to get token → link

Query

Syntax how to write queries → link

Don't forget "AND [System.TeamProject] = 'your project name'" statement if you have multiple projects under one organization or you will get all workitems which satisfy your query.

string[] fields = { };

Reference here all field names on which you want to get information.

You can see list of all your fields here → link

You can have also custom-made fields with specific formatting. In this case you will refer to them like this e.g. Custom.VendorEmailAddress (not System..)

❗ Situation: you have 3 WorkItems. None of them is assigned to person. The workItem object won't contain this column, so you will end up with exception. Make sure you apply some try-catch here.

QueryWorkItems and UpdateField return tasks so make sure to use await.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 704 1/20/2022