How to link a TFS workitem to another using command line - tfs-power-tools

How does one link an existing TFS work item to another using in command prompt. Is there a command line option for this in TFS. I know I can use tfpt.exe to create a workitem or modify it, but I cannot find an option to link a workitem to another.

Assuming you will use "Related" link type, this should link your work items..
[string]$tfsURL="http://tfs:8080/tfs"
[psobject] $tfs=[Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfsURL)
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")
$wit=$tfs.Getservice([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])
$item1=$tfs.WIT.GetWorkItem(1)
$item1.Open()
$item2=$tfs.WIT.GetWorkItem(3)
$linkType=$tfs.WIT.WorkItemLinkTypes.Item("System.LinkTypes.Related")
$witLink=New-Object Microsoft.TeamFoundation.WorkitemTracking.Client.WorkitemLink($linkType.ForwardEnd,$item2.Id)
$item1.WorkItemLinks.Add($witLink)
$item1.Validate()
$item1.Save()
$item1.Close()

Related

Wrong "ReflectedWorkItemIDFieldName" while migrating Azure DevOps Work Items

I am testing the azure-devops-migration-tools and have create a project using https://azuredevopsdemogenerator.azurewebsites.net/ (Parts Unlimited). I have generated the configuration.json and changed the Source and Target so I can test a migration, but I'm getting errors while migrating Work Items.
[15:14:41 ERR] Error running query
Microsoft.TeamFoundation.WorkItemTracking.Client.ValidationException: TF51005: The query references a field that does not exist. The error is caused by «ReflectedWorkItemId».
I've tried different options on the "ReflectedWorkItemIDFieldName" field, Scrum, Basic, Agile, Custom, empty but am still unable to migrate the work items.
How can I get the value to put on this field for the specific project?
Thanks,
Bruno
Quick Solution: Most ADO instances use the prefix 'custom' for new fields. Try "Custom.ReflectedWorkItemId" in your configuration.json to see if that resolves the problem.
More details: It's hard to tell without an actual configuration.JSON file to review. One possible problem is that you need to use the actual and full internal 'Name' of the ReflectedWorkItemID field. This doesn't show in ADO, or the Process Template when created. The recommendation is that you create a query referencing your custom field, and export the WIQL file (query file). Once you export the WIQL file, you can then open the file and see the full syntax of the custom field.
Exporting Queries: If you don't know how to do this, it can be done with VisualStudio. If you don't know how to do that, you can install this extension. It's a handy WIQL import/Export and editor. Install, and your ADO Queries with have an Edit in WIQL Editor option. Create a query that exposes your 'ReflectedWorkItemID' as a column, then edit that query in the WIQL editor and see the full names of the Reflected Work Items ID Feild. https://marketplace.visualstudio.com/items?itemName=ottostreifel.wiql-editor
SELECT
[System.Id],
[System.WorkItemType],
[System.Title],
[System.AssignedTo],
[System.ChangedBy],
[Custom.ReflectedWorkItemId]
FROM workitems
WHERE ...
I found a possible solution. I have created a custom process, change the process from the projects to this new one and add a new field. This is the field I'm using on the configuration.json and now I'm able to migrate work items
To make the migration in the "ReflectedWorkItemIDFieldName" you must do:
"Organization Settings" -> Process -> Select the process where you project are (Basic, Scrum, Agil, or CMMI).
then click on the 3 dots and create a new Inherited process.
Then with the inherited process, you are able to create a new field for each work item type. The name that you type (could be "IronMan") that name will be in your configuration file.

Intellij Idea Live Templates

I faced with the problem of writing my vcs current branch name each time I have written 'todo' comment.
Recently I learned about Intellij's 'Live Templates' which is quite comfortable to use. I tried to apply it to my problem but there's no templates to take out a branch name.
So the question is could I actually take out the name of my branch to code comments somehow?
It is possible to use the groovyScript predefined function and a script to extract the branch name. For example create the following live template:
$COMMENT$ todo [$BRANCH$]: $END$
with abbreviation "todo" and description "Inserts todo comment with branch name". Click Edit variables and give the variables the following definitions:
COMMENT:
lineCommentStart()
BRANCH (updated for 2020.2 and newer)
groovyScript("com.intellij.dvcs.repo.VcsRepositoryManager.getInstance(_editor.project).getRepositoryForFileQuick(com.intellij.openapi.fileEditor.FileDocumentManager.getInstance().getFile(_editor.document)).getCurrentBranchName()")
Skip if defined checked for both variables. The Groovy script is (unfortunately) all one line. Set applicable contexts to Everywhere.
With this live template it is now possible to type todoTab somewhere in a source file and a line comment with the branch name will be inserted. This will insert the proper line comment depending on the language of the file, or nothing in case of languages without a line comment like HTML. And should extract the branch name no matter the type of version control used (I tested with Git).
For live templates you can use predefined functions. Unfortunately there is no function to detect the current VCS branch.
But you can create a template to make work a little easier:
// TODO [$branch_name$]: $comment$
With this template, you still have to fill branch name, but you should not type symbols like [ and caret will be placed automatically.
You can also create a feature request for a new predefined function.

Move SAP package to top level

We have a subpackage thet we want to move up to the top level, so that it doesn't have any superpackage anymore.
The 'change' dialog for superpackage does not allow an empty value:
Is there another way to do this, or does the package need to be deleted and recreated?
There does not appear to be a UI function to remove that assignment. However, you could try to do this programmatically: use CL_PACKAGE_FACTORY to load the package (you'll get an instance of IF_PACKAGE), then call SET_SUPER_PACKAGE_NAME. Haven't tried it myself, though.
Looks like it's stored in table TDEVC field PARENTCL. So you can try (at your own risk) to edit the record and remove superpackage from there.

TFS 2015 Build Definition source version

When queuing a new build I want to specify a label, as says in the Tooltip (see image below) like:
LMain_TestProject_1.01.002
However, that does not work, I have to put it with this format:
LMain_TestProject_1.01.002#$/TestProject
What I have to do to only specify the source version as: LMain_TestProject_1.01.002 ??
Thanks!
This is usually because the label you created is project-scoped, not collection-scoped. In this scenario, you need to add "#/ProjectName".
Usually, when you create a label from VS, you should see the seting like following:
With this setting, the label is project-scoped. You need to enter "LTestLable#/EddieLabel" when queue build.
More information for your reference: Label scope revealed.

is it possible to reference .linq file in LinqPad

is it possible to call/reference functions in another query file beside MyExtensions in LinqPad?
You can call one script from another:
Another way to combine scripts is to dynamically execute one script from another. The Util.Run method does exactly that, and is useful in both interactive and command-line scenarios:
string htmlResult = Util.Run ("test.linq", QueryResultFormat.Html).AsString();
Note: If you feed Util.Run a relative path, it will resolve it relative to the 'My Queries' directory rather than the current directory. You can switch its behavior by specifying .\test.linq instead of test.linq in this example.
From:
LINQPad Command-Line and Scripting
No, this isn't possible right now.