1
votes

I've got a number of attachments against different work items in DevOps currently (all within the one project site). I think there are a number of attachments that have been uploaded after the sign-off date indicated, and would like to be able to pull down the data so that I can compare the attachment upload date with the sign off date.

I can see that there's an attachment count field in DevOps but I've not been able to spot anything for attachments. Is this possible? If I can get the results somehow into a spreadsheet then I can do what I need to, as the sign off date is a custom field I know I can get at.

2
Hi @James Is there any update about this ticket? Feel free to let me know if the answers could give you some help. If the answer could solve this issue, you may consider accepting one as answer. - Kevin Lu-MSFT

2 Answers

1
votes

I've got quite a lot of work items to check through unfortunately 2300(ish). Is there a max limit for the number of work items I can query at once??

Explanation:

This Powershell sample will execute the following two Rest APIs: Wiql - Query By Wiql and Work Items - Get Work Item

The Wiql - Query By Wiql Rest API will list all work items. The limit is 20000 work items. It could meet your requirements.

The Work Items - Get Work Item Rest API will get work item based on the IDs from the first Rest API.

Then you could use $expand=relations to get work item attachments.

Update:

To get all work items attachement and export to csv, you could try the following sample:

$token = "PAT"

$url="https://dev.azure.com/{Org}/_apis/wit/wiql?api-version=5.1"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

$JSON = @'
{
   "query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType]  <> ''"
}
'@

$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -Body $JSON -ContentType application/json


ForEach( $workitemid in $response.workItems.id ) 
{

echo $workitemid

$url1="https://dev.azure.com/{Org}/{Project}/_apis/wit/workitems/$($workitemid)?"  + "`$expand" + "=relations&api-version=6.0"

$response1 = Invoke-RestMethod -Uri $url1 -Headers @{Authorization = "Basic $token"} -Method Get 

#Write-Host "Pipeline = $($response1| ConvertTo-Json -Depth 100)"

$date = $response1.relations.attributes.resourceCreatedDate

$date1 = [String]$date

$Attachmentmentname = $response1.relations.attributes.name

$Attachmentmentname1 = [String]$Attachmentmentname

$workitemtitle = $response1.fields.'System.Title'

echo Workitemid: $workitemid  WorkitemTitle: $workitemtitle   Attachmentdate: $date 

$Output = New-Object -TypeName PSObject -Property @{
    id = $workitemid
    date = $date1
    Attachmentmentname = $Attachmentmentname1 
    Title = $workitemtitle
  } | Select-Object id, Title,Attachmentmentname,date
$Output | Export-Csv D:\GPoutput.csv -Append


}

Result:

enter image description here

0
votes

Sure, you can get your attachment details. Unfortunately, you're going to have to use the Azure DevOps API. The query editor is limited to only querying by and for the Attachement Count.

You will be able to get the full attachment details by using a query similar to this

Run this within postman after replacing the tokens, or directly your browser (your authentication will carry over):

https://dev.azure.com/**YOUR_ORGANIZATION**/**YOUR_PROJECT**/_apis/wit/workitems?ids=**WORK_ITEM_IDs**&api-version=6.0&$expand=relations

You'll want to comma delimit your work item Ids (For example: 1,2,3).

You'll be able to find your work item details within the relations property of the JSON:

  ...
  "relations": [
        {
            "rel": "AttachedFile",
            "url": "https://dev.azure.com/YOUR ORG/GUID/_apis/wit/attachments/GUID",
            "attributes": {
                "authorizedDate": "2021-02-15T20:13:13.333Z",
                "id": 1234567,
                "resourceCreatedDate": "2021-02-15T20:13:10.607Z",
                "resourceModifiedDate": "2020-12-18T00:31:48.663Z",
                "revisedDate": "9999-01-01T00:00:00Z",
                "resourceSize": 123456,
                "name": "TEST-ATTACHMENT.PNG"
            }
        }
    ],
  ...