i'm looking for your help, guys! I want to get Current Project Name from query, using my custom plugin.
Here is my code
WorkItemCollection queryResults = workItemStore.Query("SELECT [System.TeamProject] FROM WorkItems WHERE [System.TeamProject] = '#Project'");
foreach (WorkItem item in queryResults)
{
// SomeCode;
}
So result of Query is empty.. I have no idea why.. If i'm writing
real Project Name instead of the '#Project' it's works.. Also i tried to write #Project wihout quotes - also no result.
You can't use "#Project" in code like this. #Project is only available within a VisualStudio work item query where it can infer the team project based on your currently selected project in the Team Explorer.
You can try this code if your plugin is an WorkItemChangedEventHandler:
WorkItemChangedEvent workItemChange = (WorkItemChangedEvent)notificationEventArgs;
Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem wi = workItemStore.GetWorkItem(workItemChange.CoreFields.IntegerFields[0].NewValue);
string p = wi.Project.Name
Related
I am taking over a catalog of projects that already initiated. My job is to enter the projects into TFS and use the 'work' features. I am entering each project as an Epic...15 Epics total. When I enter an Epic is used the date I enter it as the project initiation day. Is there a way to grandfather in Epics in TFS. Adding Epics with a start date in the past? I cannot congigure the cumulative flow diagram properly without being able to back date entries.
Thanks
In Epics, the default field "CreateDate" can't be changed. It uses the date and time when the Epic created.
As a alternative, you can customize a field to use DateTimeControl, then you can select Date and change the time in this custom field:
There isn't any way to change the create date from TFS Web Portal. But if you create the work item via TFS API, you can enable the bypassrule which allow you specify the create date of the work item. Following is a code sample for this:
static void Main(string[] args)
{
string url = "http://collectionurl/";
TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri(url));
WorkItemStore wis = new WorkItemStore(ttpc.Name,WorkItemStoreFlags.BypassRules);
Project pro = wis.Projects["ProjectName"];
WorkItemTypeCollection wits = pro.WorkItemTypes;
WorkItem wi = new WorkItem(wits["Epic"]);
wi.Fields["System.Title"].Value = "Title";
wi.Fields["System.CreatedDate"].Value = Convert.ToDateTime("2016-09-01");
wi.Save();
}
Note: To use this, you must be the member of "Project Collection Administrators" security group.
Refer to this link for details: TFS API Part 48 – WorkItemControl And Bypass Work Item Rules.
Is there a way to programmatically access the "Kanban Column" for a WorkItem using the TFS 2012 API?
Using the Scrum 2.2 template, the history of a Bug or Product Backlog Item shows "[MyProject\MyTeam] Kanban Column" as a changed field whenever a work item is dragged between Kanban columns on the Board, but the field is not accessible when specifically retrieving a work item through the TFS API.
It also shows up as a changed field in the WorkItemChangedEvent object when implementing the ProcessEvent method on the Microsoft.TeamFoundation.Framework.Server.ISubscriber interface.
Workaround:
A coworker found a blogpost about creating a read-only custom field to persist the value of the Kanban Column, taking advantage of the WorkItemChangedEvent to capture the latest value. It is then possible to query on this column. One problem with this approach is that only a single team's Kanban Column can be tracked.
Update:
According to this blogpost, the Kanban Column is not a field, rather a "WIT Extension". This may help lead to an answer.
I've found a way to read the value using the TFS 2013 API, inside the ISubscriber.ProcessEvent method:
var workItemId = 12345;
var extService = new WorkItemTypeExtensionService();
var workItemService = new WorkItemService();
var wit = workItemService.GetWorkItem(requestContext, workItemId);
foreach (var wef in extService.GetExtensions(requestContext, wit.WorkItemTypeExtensionIds))
{
foreach (var field in wef.Fields)
{
if (field.LocalName == "Kanban Column" || field.LocalName == "Backlog items Column")
{
// Access the new column name
var columnName = wit.LatestData[field.Field.FieldId];
}
}
}
If you are prepared to dig into the database you can mine this information out. I don't fully understand the modelling of the teams in TFS yet but first you need to work out which field id the team of interest is storing the Kanban state in as follows (TFS 2012):
USE Tfs_DefaultCollection
SELECT TOP(10)
MarkerField + 1 as FieldId,*
FROM tbl_WorkItemTypeExtensions with(nolock)
JOIN tbl_projects on tbl_WorkItemTypeExtensions.ProjectId = tbl_projects.project_id
WHERE tbl_projects.project_name LIKE '%ProjectName%
Then replace XXXXXXXX below with the FieldId discovered above
SELECT TOP 1000
wid.Id,
wia.State,
wid.StringValue as Kanban,
wia.[Work Item Type],
wia.Title,
tn.Name as Iteration
FROM tbl_WorkItemData wid with(nolock)
JOIN WorkItemsAre wia on wia.ID = wid.Id
JOIN TreeNodes tn on wia.IterationID = tn.ID
WHERE FieldId = XXXXXXXX and RevisedDate = '9999-01-01 00:00:00.000'
ORDER BY Id
I am not familiar with the Scrum 2.2 template, but the works are the same for CMMI or Scrum templates when it comes to TFS Work Item tracking.
Try something like this:
public string GetKanbanColumn(WorkItem wi)
{
if (wi != null)
{
return wi["Kanban"].ToString();
}
return string.Empty;
}
Depending on the actual name of the column, specified in the Work Item Template XML file. Hope this helps.
I want to know how I can update the field of my bug workitem. Suppose I need to change title of my bug workitem and after doing that I should get one pop up message box that my title field has changed without using email alerts? This is the query to select the workitem of a particular team project:
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection
(new Uri("server url"));
var service = tfs.GetService<WorkItemStore>();
var qText = String.Format(#"SELECT [System.WorkItemType],
[System.Title], [System.Description], [System.Reason]
FROM WorkItems WHERE [System.TeamProject] = {0}", "'Demo1'");
I want to know the update query for changing the particular field.
Have you tried something like:
Dim workItemStore as WorkItemStore = tfs.GetService(Of WorkItemStore)()
Dim wi as WorkItem = workItemStore.GetWorkItem(workItemNumber)
wi.Fields("System.Title").Value = "Foo Title"
wi.Save()
I don't think WIQL supports dml commands. You are probably going to have to use the object model to do this: http://msdn.microsoft.com/en-us/library/bb130323.aspx
i am developing report plugin for jira where i need to get assignee for given duration.it could be diffrent than current assignee in given duration.
now i am building my query in report like below.
JqlQueryBuilder queryBuilder = JqlQueryBuilder.newBuilder();
query = queryBuilder.where().updatedBetween(stdate,endDate).and().assignee() in(status_val).buildQuery();
return searchProvider.searchCount(query, remoteUser);
i want to get the count for prior assigned issues for given duration.
please let me know how i can use Was clause with assignee and updatedbetween dates.
regards,
tousif shaikh.
Try reading this answer. In short, you'll need to define a new clause and use it in your query, like this:
JqlQueryBuilder builder = JqlQueryBuilder.newBuilder();
WasClauseImpl wasClause = new WasClauseImpl("status", Operator.WAS, new SingleValueOperand("Resolved"), new TerminalHistoryPredicate(Operator.AFTER, new SingleValueOperand(3500000L)));
JqlClauseBuilder clauseBuilder = JqlQueryBuilder.newClauseBuilder(wasClause);
Query query = clauseBuilder.buildQuery();
I´m writing an extension to TFS that can run queries. As I have seen, before running the query with the TFS API, all defined variables must be replaced.
I have looked at the default TFS variables here and I can understand all except for #Today variable.
The main problem with the #Today variable is that you can add operators to it like:
[Source].[Microsoft.VSTS.Common.ActivatedDate] = #today - 7
Do I need to replace the variable with the current date (and time?) and let the query engine do the math, or should I do the math before passing it to the query engine?
You do not need to replace #Today with anything, you can just run the query "as is".
For example running the following in Linqpad:
using (var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(CollectionAddress)))
{
tfs.EnsureAuthenticated();
var server = tfs.GetService<WorkItemStore>();
server
.Query("select * from WorkItems where System.CreatedDate > #today - 1")
.Cast<WorkItem>()
.Select(wi => new { wi.Id, wi.CreatedDate, })
.Dump(); //This is a http://LinqPad.net extension method.
}
Returns all the work items logged in my TFS Collection in since this morning.
The Work Item Query Language (WIQL) parser must take care of these things for you.