Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
update wef field to set the work item on the board column (#246)
Browse files Browse the repository at this point in the history
* update wef field to set the work item on the board column

* minor fixes
  • Loading branch information
danhellem authored May 13, 2019
1 parent edb0cde commit d95b476
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
35 changes: 35 additions & 0 deletions ClientLibrary/Samples/Work/BoardsSample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.VisualStudio.Services.WebApi;
using Microsoft.TeamFoundation.Core.WebApi.Types;
using Microsoft.TeamFoundation.Work.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.TeamFoundation.Core.WebApi;

namespace Microsoft.Azure.DevOps.ClientSamples.Work
{
[ClientSample(WorkWebConstants.RestArea, "boards")]
public class BoardsSample : ClientSample
{
[ClientSampleMethod]
public Board GetTeamStoriesBoard()
{
VssConnection connection = Context.Connection;
WorkHttpClient workClient = connection.GetClient<WorkHttpClient>();

TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context);
WebApiTeamRef team = ClientSampleHelpers.FindAnyTeam(this.Context, project.Id);

TeamContext context = new TeamContext(project.Id, team.Id);
context.Team = team.Name;
context.Project = project.Name;

Board board = workClient.GetBoardAsync(context, "Stories").Result;

Context.Log("Columns for 'Stories' Board for Project '{0}' and Team '{1}'", context.Project, context.Team);
Context.Log("");

return board;
}
}
}
52 changes: 52 additions & 0 deletions ClientLibrary/Samples/WorkItemTracking/WorkItemsSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,58 @@ public WorkItemTemplate ReplaceTemplate()
return result;
}

[ClientSampleMethod]
public WorkItem UpdateWorkItemBoardColumn()
{
string targetColumn = "Testing"; //need to set to match your board

VssConnection connection = Context.Connection;
WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>();

JsonPatchDocument patchDocument = new JsonPatchDocument();

//create a work item that drops into the new column by default
WorkItem workItem = this.CreateWorkItem("Board Column Test", "User Story");

string wefField = "";

//find the WEF field
//todo: do something smarter rather than loop through all fields to find the WEF
foreach (var field in workItem.Fields)
{
if (field.Key.Contains("_Kanban.Column"))
{
wefField = field.Key.ToString();
break;
}
}

//build a patch document to update the WEF field
patchDocument.Add(
new JsonPatchOperation()
{
Operation = Operation.Test,
Path = "/rev",
Value = "1"
}
);

patchDocument.Add(
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/" + wefField,
Value = targetColumn
}
);

WorkItem result = witClient.UpdateWorkItemAsync(patchDocument, Convert.ToInt32(workItem.Id)).Result;

Context.Log("Updated work item to teams board column '" + targetColumn + "'");

return result;
}

[ClientSampleMethod]
public void DeleteTemplate()
{
Expand Down

0 comments on commit d95b476

Please sign in to comment.