Arsalan Younus
Arsalan Younus

Reputation: 9

TFS Api not giving custom states in a customized Process Template on Dev Azure

I have added a custom state in a Scrum Process Template but API is not giving newly added state until I create a new project based on that customized process template.

enter image description here

Every time I have to create project as a resolution to resolve this issue. What can I do to fix this issue?

WorkItemStore workItemStore = this.tfsTeamProjectCollection.GetService<WorkItemStore>();

            int projectConunt = workItemStore.Projects.Count;

            for (int i = 0; i < projectConunt; i++)
            {
                WorkItemTypeCollection workItemTypeCollection = workItemStore.Projects[i].WorkItemTypes;

                for (int j = 0; j < workItemTypeCollection.Count; j++)
                {
                    string workitemType = workItemTypeCollection[j].Name;

                    for (int k = 0; k < workItemTypeCollection[j].FieldDefinitions.Count; k++)
                    {
                        Microsoft.TeamFoundation.WorkItemTracking.Client.FieldDefinition fieldDefinition =
                            workItemTypeCollection[j].FieldDefinitions[k];
                       
                        if (filedRefName == fieldDefinition.ReferenceName)
                        {
                            List<string> allowedValues = new List<string>();

                            foreach (var allowedValue in fieldDefinition.AllowedValues)
                            {
                                allowedValues.Add(allowedValue.ToString());
                            }

                            WorkItemFieldsInfo workItemFieldInfo = workItemFieldsInfo.Find(st => st.Type == workitemType);

                            if (workItemFieldInfo == null)
                            {
                                workItemFieldsInfo.Add(new WorkItemFieldsInfo()
                                {
                                    Type = workitemType,
                                    AllowedValues = allowedValues
                                });
                            }
                            else
                            {
                                List<string> unionFields = workItemFieldInfo.AllowedValues.Union(allowedValues).ToList();
                                workItemFieldInfo.AllowedValues = unionFields;
                            }

                            break;
                        }
                    }
                }
            }

Upvotes: 0

Views: 89

Answers (1)

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30363

I cannot reproduce this issue. I used below rest api and it worked all fine. See here.

GET https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/states?api-version=6.1-preview.1

You can get the processid using below rest api

GET https://dev.azure.com/{organization}/_apis/work/processes?api-version=6.1-preview.2

Upvotes: 0

Related Questions