cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
HeadInTheCloud
Advocate II
Advocate II

How can I add a Hyperlink to a DevOps work item using a flow?

My flow needs to update a DevOps work item with a hyperlink. This can be done manually through the DevOps user interface by adding an existing item and selecting Hyperlink as the link type. However, in the Flow, the Update  Work Item template does not allow Hyperlink as a Link Type. I put Hyperlink into the field, but the update errored with 'Unknown relation type System.LinkTypes.Hyperlink'. I really need this. Please guide me to how I can add the Hyperlink.

 

 
1 ACCEPTED SOLUTION

Accepted Solutions

I figured out how to do it - it took me all day - but I am tickled to find a solution using the "Send an HTTP Request to Azure DevOps" action.

 

See the following Flow action where the variable IDOfWorkItem is the work item to be updated and the variable DEVOPSAPIURI is URL:  https://dev.azure.com/<organization>/<project>/_apis/wit/workitems/@{variables('IDOfWorkItem')}?api-.... The AddLinkJSON below uses a RelatedItemURL that is in the form "https://....". Setting the Content-Type was one key to getting this to work.

 

Adding a hyperlink to a work item using Flow HTTP PATCH.JPG

Here's proof:

Successful flow to add a link.JPG

 

and the link now appears on the work item

Added link on work item.JPG

View solution in original post

14 REPLIES 14
v-bacao-msft
Community Support
Community Support

 

Hi @HeadInTheCloud ,

 

It seems we can't add hyperlink to work item, please check this similar thread:

https://developercommunity.visualstudio.com/content/problem/308914/not-able-to-add-hyperlink-to-work...

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-bacao-msft Thanks for the reply to my post. I'm not sure that applies to my issue since I am able to add a Hyperlink to a Work Item via the Web UI by going to the Links Tab and selecting the Add Link - Existing Item drop down option. That opens the form shown below and I can enter the URL and select Hyperlink in the Link Type. 

Adding a hyperlink to a work item in Azure DevOps (Existing)

 

[edit - the UI image is in the next reply]

@v-bacao-msft Thanks for the reply to my post. I'm not sure that applies to my issue since I am able to add a Hyperlink to a Work Item via the Web UI by going to the Links Tab and selecting the Add Link - Existing Item drop down option. That opens the form shown in the first screen shot below and I can enter the URL and select Hyperlink in the Link Type. My problem is that I need to add a link to a Dynamics CRM record to a Work Item in a Flow. Options in the DevOps "Update A Work  Item" action allows me to add a link to another Work Item (see second screen shot), but not to a CRM item. IMO, that's an operation Flow should offer. "Create A Work Item" appears to have the same limitation.

 

Adding a hyperlink to a work item in Azure DevOps (Existing).JPG

 

Here's what Flow offers me for Link Type options - only links to other work items -

 

Link types available when updating a work item via Flow.JPG

I figured out how to do it - it took me all day - but I am tickled to find a solution using the "Send an HTTP Request to Azure DevOps" action.

 

See the following Flow action where the variable IDOfWorkItem is the work item to be updated and the variable DEVOPSAPIURI is URL:  https://dev.azure.com/<organization>/<project>/_apis/wit/workitems/@{variables('IDOfWorkItem')}?api-.... The AddLinkJSON below uses a RelatedItemURL that is in the form "https://....". Setting the Content-Type was one key to getting this to work.

 

Adding a hyperlink to a work item using Flow HTTP PATCH.JPG

Here's proof:

Successful flow to add a link.JPG

 

and the link now appears on the work item

Added link on work item.JPG

Thanks for sharing this solution.  Only thing I can't seem to figure out is to how to add a comment.  I've tried adding these to the JSON with no success

 

"comment":"sample comment"

"linkcomment":"sample comment"

"link comment":"sample comment"

 

I've also tried the above with the L & C capitalized in case things are case sensitive

 

Any guidance is much appreciated.

HeadInTheCloud
Advocate II
Advocate II

I haven't added a comment to a work item, but I have retrieved comments with an HTTP request and they are returned in an array. I hope that helps. If you have figured out how to do it, it would be great if you could post the solution.

 

Hi @AnthonyPSlalom ,

you can refer the code below to add the comment.

thomas05_0-1627357062782.png

 

Hi I realise this is an old post but I was hoping you could help. I have tried to follow your solution but am getting this issue: No api-version was supplied for the "PATCH" request

Sorted it thanks 🙂

I´m sending this JSON

{
"path": "/relations/-",
"op": "add",
"value": {
"url": "https://www.google.de",
"attributes": {
"comment": "test"
},
"rel": "Hyperlink"
}
}

but receiving following error message

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"Value {\r\n \"url\": \"https://www.google.de\",\r\n \"attributes\": \"System.Collections.Hashtable\",\r\n \"rel\":
\"Hyperlink\"\r\n} does not match the expected type
Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItemRelation.","typeName":"Microsoft.VisualStudio.Services.Common.VssPropertyValidationException,
Microsoft.VisualStudio.Services.Common","typeKey":"VssPropertyValidationException","errorCode":0,"eventId":3000}
In **truncated**
+ ... dWorkItem = Invoke-RestMethod -Uri $url -Method patch -UseDefaultCred ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

 Do you have an idea?

 

I´m using the onPremises Version Dev18.M170.8

You may try to replace the value of op field with 0 instead of "add".

thomas05_2-1656405802183.png

 

The constant Operation.Add is defined in the file below and I found the value is 0.

thomas05_0-1656405689349.png

 

dfoxg
New Member

Thanks for your fast reply!

 

Changing the "op" from "add" to 0 doesnt fix the issue, I still get the same error.

When I remove the "attributes" JSON-Key, the hyperlink is getting created without the comment. 

 

After some research I found the API-Description of the WorkItemRelation Class which shows the variable "title". When I set this key the error is gone, but the hyperlink had also no comment.

It works well as I am using the javascript SDK. 
Maybe the difference is caused by different SDK implement.

dfoxg
New Member

That could be since I´m not using any SDK. I´ve implemented the API-Call in plain powershell:

function Get-WorkItem-URLPatch($targetURL) {
$nestedObject = @{}
$nestedObject["rel"] = "Hyperlink"
$nestedObject["url"] = $targetURL
$nestedObject["attributes"] = @{
comment = "test"
}

$object = @{}
$object["op"] = "add"
$object["path"] = "/relations/-"
$object["value"] = $nestedObject
ConvertTo-JSON $object | Write-Host
return $object
}

function Update-WorkItem($workitem, $workitemPatchCollection) {
$url = $tfsBaseURL + "wit/workitems/" + $workitem.id + "?api-version=6.0"
$patchJSON = ConvertTo-Json $itemPatchCollection
$utf8PatchJson = [System.Text.Encoding]::UTF8.GetBytes($patchJSON)
$patchedWorkItem = Invoke-RestMethod -Uri $url -Method patch -UseDefaultCredentials -Body $utf8PatchJson -Headers @{'Content-Type' = 'application/json-patch+json' }
return $patchedWorkItem
}

$itemPatchCollection += Get-WorkItem-URLPatch "https://www.google.de"
$updated = Update-WorkItem $workitem $itemPatchCollection

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (1,798)