Skip to main content

Notifications

Power Automate - Building Flows
Answered

Condition failing matching task ID to variable

Like (0) ShareShare
ReportReport
Posted on 2 Jan 2025 10:11:00 by 13
Hi all,
 
This should be simple but i'm struggling and wondering if you can help please.
 
I have a flow that creates a Task in Planner once a list item has been added which works well.  Now I am trying to update that list entry once a task has been marked as complete. 
My flow works but the condition always shows as a non match and therefore fails to update 
 
For clarity flow one sets Task ID as the Sharepoint list ID 
 
Writes the task ID into the title of the task following a (:)
 
 
Flow 2  gets the task list 
  

 
determines where the ID string is following the :  this could be any number dependent on how long the list gets 


Should match the list ID with the 
 
The flow runs but never managed to match the condition that takes the flow down the YES route.
 
Any help would be greatly appreciated.
 
Thanks
 
Mand 
 
  • Verified answer
    TM-08101454-0 Profile Picture
    TM-08101454-0 13 on 03 Jan 2025 at 17:22:06
    Condition failing matching task ID to variable
    Thanks for the advice all.
     
    I have managed to resolve this at last !

    Solution a little different than all suggested and as follows. 
     
    Hopefully it helps someone else out there looking for the same thing.  
     
    Note:  I have a flow running that converts a list entry into a task and includes the Task ID in the end of the title followed by a (:) the formula  looks for this and picks up the numbers following the (:) for the matching to take place 

     
     
    1. PLANNER:  When a task is completed 
    Group id:   <Enter your group>
    Plan id:  <Enter your planner name >
     
    2. PLANNER: Get task details 
     
    3. COMPOSE

    Press (fx) and insert the following 
     
    int(if(and(not(empty(triggerOutputs()?['body/title'])),contains(triggerOutputs()?['body/title'],':')),substring(triggerOutputs()?['body/title'],add(indexOf(triggerOutputs()?['body/title'],':'),1),sub(length(triggerOutputs()?['body/title']),add(indexOf(triggerOutputs()?['body/title'],':'),1))),''))
     
    4. GET ITEMS Sharepoint list 
    Site address:<Enter address>
    List name: <Enter list name>

    5. FILTER ARRAY 
     
    6.CONDITION
     
    press (fx) for the input and type the following 

    length(body('Filter_array'))

    7. UPDATE ITEM if True 

    NB: Use the Outputs from compose as the ID 


     
     
  • TM-08101454-0 Profile Picture
    TM-08101454-0 13 on 02 Jan 2025 at 13:07:34
    Condition failing matching task ID to variable
    When i try this I now get the error below and the flow fails 

    Action 'For_each_1' failed: The execution of template action 'For_each_1' failed: the result of the evaluation of 'foreach' expression '@outputs('Get_task_details')?['body/id']' is of type 'String'. The result must be a valid array.
     
     
  • Expiscornovus Profile Picture
    Expiscornovus 31,039 on 02 Jan 2025 at 11:01:04
    Condition failing matching task ID to variable
     
    You can move the condition/check to the Filter Query field of the Get Items, this way you don't have to loop through all the items.
     
    Try something like the below (copy/paste it into the Filter Query field)
     
    ID eq '@{split(triggerOutputs()?['body/title'], 'Task ID:')[1]}'



    Happy to help out 😁

    I share more #PowerAutomate and #SharePointOnline content on my Blog, Bluesky profile or Youtube Channel
  • Suggested answer
    VASANTH KUMAR BALMADI Profile Picture
    VASANTH KUMAR BALMADI 218 on 02 Jan 2025 at 10:42:15
    Condition failing matching task ID to variable
    Hi,

    This issue is likely caused by a mismatch in how the Task ID is being extracted, stored, or compared between the Planner task and the SharePoint list item. Let’s break it down and ensure the logic works as intended.

    Steps to Fix the Flow

    Flow 1: Create a Task and Write Task ID

    1. Action: Create a Task in Planner

      • Ensure the title of the task includes the Task ID from the SharePoint list in the format you’re expecting, e.g., "Task Title:123" where 123 is the list item ID.
    2. Action: Store Task ID in SharePoint

      • Store the Task ID in a separate SharePoint column (e.g., PlannerTaskID) rather than relying solely on the title.

    Flow 2: Update SharePoint When Task is Complete

    1. Trigger: Task Marked as Complete in Planner

      • Use a trigger such as "When a task is completed" to detect when the task is marked as complete in Planner.
    2. Action: Get Tasks List

      • Use "List tasks in Planner" to retrieve all tasks in the planner.
    3. Extract Task ID

      • Use an Expression to extract the numeric ID after the colon (:) from the task title:
        substring(outputs('Get_Task_Title'), add(indexOf(outputs('Get_Task_Title'), ':'), 1), length(outputs('Get_Task_Title')))
        • Replace outputs('Get_Task_Title') with the dynamic content for the task title.
        • This extracts everything after the colon.
    4. Action: Retrieve SharePoint List Items

      • Use the "Get items" action to retrieve items from the SharePoint list.
    5. Condition: Compare IDs

      • Ensure that you’re comparing the extracted Task ID with the corresponding SharePoint field.
        • Add a Condition:
          • Left: substring(outputs('Get_Task_Title'), ...)
          • Right: SharePoint List ID
      • Ensure both values are treated as strings or integers depending on how they’re stored.

    Key Considerations

    1. Trim Whitespaces
      Ensure there are no extra spaces around the Task ID. Use the trim() function to clean up the strings:

      trim(substring(outputs('Get_Task_Title'), add(indexOf(outputs('Get_Task_Title'), ':'), 1), length(outputs('Get_Task_Title'))))
    2. Check for Case-Sensitivity
      String comparisons in Power Automate are case-sensitive. Use the equals() function for comparisons:

      equals(outputs('Task_ID'), outputs('SharePoint_ID'))
    3. Use Logging for Debugging
      Add Compose actions before the condition to log the extracted Task ID and the SharePoint ID for debugging. This will help identify mismatches.

    4. Store Task ID Explicitly
      Instead of embedding the Task ID in the title, store it in a dedicated Planner task field or the SharePoint list to simplify the comparison logic.

    Simplified Flow Logic

    1. Trigger: When a task is marked as complete in Planner.
    2. Action: Get task details and extract Task ID.
    3. Action: Retrieve matching SharePoint list item using a filter query:
      PlannerTaskID eq '123'
    4. Condition: Check if a matching item exists.
    5. Action: Update the SharePoint list item.

    Debugging Tips

    • Run the flow with test data and check the outputs of each step in the run history.
    • Validate that the Task ID is extracted correctly and matches the format of the SharePoint ID.
    • If the flow works for some items and not others, review task titles for inconsistent formats.
    ----------------------------------------------------------------------------------
    If this Post helped you, please click "Does this answer your question" and give it a like to help others in the community find the answer too!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Kickstarter Events…

Register for Microsoft Kickstarter Events…

Tuesday Tip #12 Start your Super User…

Welcome to a brand new series, Tuesday Tips…

Tuesday Tip #13 Writing Effective Answers…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 144,940

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,523

Leaderboard
Loading started