cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Mustaque_Ehiya
Level: Powered On

How to set conditions to avoid duplicate Tasks creation for a User Story

Hi All,

I created a MS Flow to create 9 tasks (Dev, Testing and BA tasks) as a child for a new user story when it is assigned.

It works fine but it is getting duplicated every time when the story is assigned back from Unassigned to a resource.

I tried to get the count of related tasks for the user story before creating them but couldn't find any default conditions to get that.

Is there any other condition to set to avoid this duplicate task creations? Please assist me with this flow.

Thanks,

Mustaque

1 ACCEPTED SOLUTION

Accepted Solutions
Dual Super User
Dual Super User

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

Hi @Mustaque_Ehiya , 

 

Please refer to the flow below: 

 

To get the work items related to the user story, you will have to send a HTTP request for that. But before sending this request -> Go to Azure DevOps -> Queries -> My Queries -> Create a new blank query and save it. (In this example let us say TestNew). 

 

After you have done this, in the flow under the trigger create an action as shown. Very carefully populate all the fields. (here 'yashTest' is my project, replace it with yours)

 

Body : {
"name" : "TestNew",
"queryType" : "tree",
"wiql" : "SELECT [System.Id],[System.Title],[System.State] FROM workitemLinks WHERE([Source].[System.WorkItemType] = 'Task' AND [Source].[System.Id] = )AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward')AND ([Target].[System.WorkItemType] = 'Task')MODE (Recursive)"
}

in the "wiql" near the [System.Id] = select the ID of the work item retrived from the trigger action (the original trigger request that has the id of the assigned work item)

 

 

FlowDev.png

 

Now, create a new string variable to get the query ID and put the foloowing expression in the expression editor and add it to the string value.

 

body('Send_an_HTTP_request_to_Azure_DevOps')['id']

New add another action: Get Query Results with the query ID in the previous step. This will fetch you a list of the work items related to the assigned work item. You can iterate thorough this to check if the items exist and if not create them with Create Work Item Action. 

flowdev2.png

Hope this Helps. 

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

26 REPLIES 26
Dual Super User
Dual Super User

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

Hi, 

 

You could do try doing it this way: 

1. When a task is assigned -> Get the List of Work Items

2. Initialise a variable array and prepopulate that with the task items you are creating/ want to create

3. Start a loop and iterate through, if there are task items already created do nothing or else create a task item from the array. 

//You could also get a list of task items and pass them into an array -> check if the array is non empty and then create follow up actions. Please refer to the screenshot below; 

azdeflow.png

 

Thanks,

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Mustaque_Ehiya
Level: Powered On

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

 
 
 
 
As I am new to this Flow, I might need more help to set this condition.
 
 
 
 
 
 
I set a condition to create a test bug based on a condition to check for the TASKS and it is creating 15 bugs checking for the 15 different WORK items.
Can i have your email ID so that I can share my flow for you to check and modify that flow?
 
I am not able to attach anything in this forum.
Dual Super User
Dual Super User

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

Hi @Mustaque_Ehiya , 

 

You could post screenshots of your flow here on the forum. (Just so that other community members could also have a look and share comments in case I am unable to assist you). 

 

You can reach out to me on yashagarwal1651@yahoo.com. 

 

 

Thanks,

Mustaque_Ehiya
Level: Powered On

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

 

hi All - this is the below flow I am trying to build on work item assignment.  Need to set a condition to check if the user story has any existing task created; else create tasks. 

Task.png

Dual Super User
Dual Super User

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

Hi @Mustaque_Ehiya 

 

Please refer to the flow screenshot below:

azdeflow.png

Using the action List work items you can get the current ones and iterate them to check if there is a current entry by the same work item. You can define an array and populate the work items in that to check with the ones already there. If the condition is not met, add the create action under no and proceed. 

 

Hope this helps. 

 

Thanks.

Mustaque_Ehiya
Level: Powered On

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

@yashag2255- Not able to use the "List Work Items" as that requires a WORK ID to filter - same with "Get Work Item details".   

 

 work item IDs.PNG

 

Thanks,

Mustaque

Dual Super User
Dual Super User

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

Hi @Mustaque_Ehiya , 

 

Yes. I tried working with that and I wanted to check, are you trying to compare the work items with all the workitems in that path or is it that you are trying to get the work items that are a part (linked) to the work item being assigned?

 

 

Thanks, 

Mustaque_Ehiya
Level: Powered On

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

@yashag2255  I need to get the related workitems that are linked with that user story.

 

Thanks

 

Dual Super User
Dual Super User

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

Hi @Mustaque_Ehiya , 

 

Please refer to the flow below: 

 

To get the work items related to the user story, you will have to send a HTTP request for that. But before sending this request -> Go to Azure DevOps -> Queries -> My Queries -> Create a new blank query and save it. (In this example let us say TestNew). 

 

After you have done this, in the flow under the trigger create an action as shown. Very carefully populate all the fields. (here 'yashTest' is my project, replace it with yours)

 

Body : {
"name" : "TestNew",
"queryType" : "tree",
"wiql" : "SELECT [System.Id],[System.Title],[System.State] FROM workitemLinks WHERE([Source].[System.WorkItemType] = 'Task' AND [Source].[System.Id] = )AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward')AND ([Target].[System.WorkItemType] = 'Task')MODE (Recursive)"
}

in the "wiql" near the [System.Id] = select the ID of the work item retrived from the trigger action (the original trigger request that has the id of the assigned work item)

 

 

FlowDev.png

 

Now, create a new string variable to get the query ID and put the foloowing expression in the expression editor and add it to the string value.

 

body('Send_an_HTTP_request_to_Azure_DevOps')['id']

New add another action: Get Query Results with the query ID in the previous step. This will fetch you a list of the work items related to the assigned work item. You can iterate thorough this to check if the items exist and if not create them with Create Work Item Action. 

flowdev2.png

Hope this Helps. 

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

Mustaque_Ehiya
Level: Powered On

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

Hi,

 

I created a blank query - 'GetTasks' - as mentioned 

 

blank query.PNG

and referenced the same in the MS FLOW with one modification - Modified the workitemtype as USER STORY instead of tasks --> Tested this in the WIQL editor and it was returning results correctly.

query ado.PNG

 

When I test this flow, I get Unauthorized error in this task.   Can you plese let me what the error is and how to fix this error?

 

unauthorized error.PNG

 

 

Dual Super User
Dual Super User

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

Hi @Mustaque_Ehiya 

 

You are not using the correct Relative URI. Please refer to the one in my screenshot and replicate. 

 

Thanks

Mustaque_Ehiya
Level: Powered On

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

@yashag2255  - Thanks for correcting the URI.  After updating it the earlier error got fixed and now I get the 404 error.

 

Please find below the error SS.

notfounderror.PNG404.PNG

 

Thanks,

Mustaque

 

Dual Super User
Dual Super User

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

Hi @Mustaque_Ehiya 

 

Can you please go to Azure DevOps and check what is the content of the query there? Has the query been updated based on what you have tried to patch from the flow?

Mustaque_Ehiya
Level: Powered On

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

@yashag2255- below is the ADO queries I tried with.. GetTasks and GetTasks1..

both returning the 404 error.

 

GetTasks -.PNGgettasks1.PNG

 

Thanks,

Mustaque

 

 

 

 

Dual Super User
Dual Super User

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

Hi @Mustaque_Ehiya , 

 

Are these queries updated from the create/ update query of the flow that you ran? or have you created a new one on the Azure DevOps portal? I can see that the Get Tasks query is empty. And in the Get Task1 there is no unique identifier. 

 

Thanks

Mustaque_Ehiya
Level: Powered On

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

@yashag2255- I created a query in ADO as you mentioned in the post.  (Go to Azure DevOps -> Queries -> My Queries -> Create a new blank query and save it. (In this example let us say TestNew). 

Dual Super User
Dual Super User

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

@Mustaque_Ehiya 

 

can you share a screenshot of the HTTP request action from Flow. I am guessing that something is missing here. I have tested the same thing in my ssystem and it works. 

 

 

Mustaque_Ehiya
Level: Powered On

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

@yashag2255- Pls find the image for the HTTP Request.  

 

queryADO.PNG

Dual Super User
Dual Super User

Re: How to set conditions to avoid duplicate Tasks creation for a User Story

Hi @Mustaque_Ehiya 

 

Please confirm these parts of the Relative URI: 

1. what is MustaqueEhiya (i am guessing this is the project name)

2. What is ADO_Features_review? 

3. Please change "Queries" to "queries" in the relative URI. 

 

Please note that you just have to metion the project name in the query (pts 1 and 2) projectName/_apis/wit/queries/My Queries/GetTasks1?api-version=5.0

 

Hope this Helps!

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors (Last 30 Days)
Users online (4,930)