Search code examples
azure-devopstfs-workitem

Azure DevOps Work Item Attachment Upload Date


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.


Solution

  • 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