Skip to main content

Notifications

Power Automate - Building Flows
Suggested answer

Cancel Pending Teams Approval Flow

(0) ShareShare
ReportReport
Posted on by 42
Hello,
I have a model-driven app in one environment and my teams approval requests are in a different environment. In order to get my approvals to work properly, I have done the following:
  • Environment #1 = Flow Part 1A - Approval Flow is triggered from a CE Opportunity and all the details are saved to a SharePoint list
  • Environment #2 = Flow Part 2A - When an item is created in the SharePoint list, it creates a Teams Approval. The result (approve/reject) updates the SharePoint item
  • Environment #2 = Flow Part 2B - When an item is modified in the SharePoint list, it checks if second level of approval is required. Flow cancels if not required but if it is the Teams Approval is created and the result updates the SharePoint item
  • Environment #1 = Flow Part 3 - When an item is modified in the SharePoint list, it checks if all levels of approval have been completed. The details (approve/reject) from the SharePoint list are saved to CE Opportunity
This process works but I need to be able to cancel pending Teams Approvals when the CE Opportunity is updated with a value that no longer requires the approval. Here is what I have so far:
  • Environment #1 = Flow Part 1B  
    • If CE Opportunity has an Approval in Pending Status but trigger is FALSE, update Approval from Pending to Cancelled
    • Get items from SharePoint list, where Title column = Opportunity Number
    • Compose: first(body('Get_items')['value'])['Title']
    • Update SharePoint Item to Cancelled
    • ISSUE #1: first time this flow runs, it fails with this error message: Action 'Compose' failed: Unable to process template language expressions in action 'Compose' inputs at line '0' and column '0': 'The template language expression 'first(body('Get_items')['value'])['Title']' cannot be evaluated because property 'Title' cannot be selected. The flow will run a second time and succeed with the full flow. I want to add a condition so if the Title is null, the flow cancels but I used the Compose specifically because when I tried to use a Condition previously, it created a For Each that updated every single item in the SharePoint list
  • Environment #2 = Flow Part 2C
    • When SharePoint list is modified, check if has Cancelled Value
    • If yes, update the correct row in the Approvals entity to Cancel the Pending Approval
    • ISSUE #2: this process works to cancel the pending approval for the manager in Teams however the Flow Part 2A which triggered the approval doesn't get the message that it has been cancelled. The Flow eventually times out and tracks as a Failed Run
If anyone can help me with the 2 issues I would really appreciate it!
 
PART 1B
PART 2A
  • kagostinho Profile Picture
    kagostinho 42 on at
    Cancel Pending Teams Approval Flow
    I think I figured out how to tweak the formula to get ISSUE #1 - 1B formula to work:
     
    if(greater(length(body('Get_items')?['value']), 0), first(body('Get_items')?['value'])?['Title'], 'Null')
     
    Still trying to figure out ISSUE #2
     
  • kagostinho Profile Picture
    kagostinho 42 on at
    Cancel Pending Teams Approval Flow
    Hi @abm abm - unfortunately that didn't work:
    Action 'Compose' failed: Unable to process template language expressions in action 'Compose' inputs at line '0' and column '0': 'The template language function 'if' expects its first parameter to be of type boolean. The provided value is of type 'Integer'. Please see https://aka.ms/logicexpressions#if for usage details.'.
  • Suggested answer
    abm abm Profile Picture
    abm abm 32,265 on at
    Cancel Pending Teams Approval Flow
    Hi
     
    This could be because there are no data returned from the Get Items step. Try the below expression.
     
    if(length(body('Get_items')?['value']), first(body('Get_items')?['value'])?['Title'], 'No Data')
     

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,858

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,505

Leaderboard