getting linked workitem in azure devops using python

I’m using Azure Devops module of python to get the linked workitems to the userstory in Tree structure(parent,child link)

I tried this code

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
from azure.devops.v7_1.work_item_tracking.models import Wiql
from variable import personal_access_token,org,project

# Replace with your personal access token and organization URL
personal_access_token = personal_access_token
organization_url = org
project_name = project

# Create a connection to the Azure DevOps organization
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)

# Get the work item tracking client
wit_client = connection.clients.get_work_item_tracking_client()

# Define a WIQL (Work Item Query Language) query to get work items
wiql_query = Wiql(
    query=f"""
    SELECT
        [System.Id],
        [System.WorkItemType],
        [System.Title],
        [System.AssignedTo],
        [System.State],
        [System.Tags]
    FROM workitems
    WHERE
        (
            [Source].[System.TeamProject] = 'DevOps RnD'
            AND [Source].[System.Id] = 326797
        )
    AND (
            [System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward'
        )
    ORDER BY [System.Id]
    MODE (Recursive)
    """
)

wiql_result = wit_client.query_by_wiql(wiql=wiql_query)

but this gives error on this line

wiql_result = wit_client.query_by_wiql(wiql=wiql_query)

saying

Exception has occurred: AzureDevOpsServiceError
The MODE keyword can not be used inside work item query. The error is caused by «Recursive».

Question: How do I resolve this Error?

Any help would be really appreciated!

2

Test the same Python sample and I can reproduce the same issue.

The cause of the issue could be that the Wiql() doesn’t support Mode keyword in wiql definition.

To use the wiql format in your python sample, you can use the Rest API: Wiql – Query By Wiql in the Python script to get the work items.

POST https://dev.azure.com/{organization}/{project}/_apis/wit/wiql?api-version=6.0

Here is an example:

import requests
from requests.auth import HTTPBasicAuth


personal_access_token = 'PAT'
organization_url = 'https://dev.azure.com/OrganizationName'
project = 'ProjectName'
parent_work_item_id = 326797  # Replace with your parent work item ID


wiql_url = f'{organization_url}/{project}/_apis/wit/wiql?api-version=6.0'


wiql_query = {
    "query": f"""
    SELECT
        [System.Id],
        [System.WorkItemType],
        [System.Title]
    FROM workitemLinks
    WHERE
        (    
            [Source].[System.TeamProject] = 'DevOps RnD'
            And [Source].[System.Id] = {parent_work_item_id}
        )
        AND (
            [System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward'
        )
     ORDER BY [System.Id]
     MODE (Recursive)
    """
}


response = requests.post(wiql_url, json=wiql_query, auth=HTTPBasicAuth('', personal_access_token))
response.raise_for_status()
wiql_results = response.json()

print(f"{wiql_results }")

Result:

It will return System.LinkTypes.Hierarchy-Forward type linked work item. The Source -> ID is Parent work item id and Target -> ID is Child work item ID.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật