Skip to main content

Notifications

Community site session details

Community site session details

Session Id : qUqHO8toEKRh8o8AAA2rCR
Power Automate - General Discussion
Answered

Compare values using condition

Like (0) ShareShare
ReportReport
Posted on 2 Jan 2021 13:12:38 by 98

Hi,

 

I am comparing two values using the condition:

 

1. Value inputted by the user (based on the comment he/ she inputted when approving the e-mail)

 

2. 100000

 

My flow looked like this:

 

SK_Tan_1-1609593055310.png

 

 

However, my flow failed with the following error msg.

 

Unable to process template language expressions for action 'Condition_8.1' at line '1' and column '2863': 'The template language function 'greaterOrEquals' expects two parameter of matching types. The function was invoked with values of type 'String' and 'Integer' that do not match.'.

 

SK_Tan_0-1609592929796.png

 

Can anyone help?

 

Thanks in advance!

SK

 

 

  • SK_Tan Profile Picture
    98 on 11 Jan 2021 at 00:44:24
    Re: Compare values using condition

    Thank you. Your detailed inputs are what I looking for as I am relatively new this tool.

     

    Looking ahead more valuable sharing like this.

  • ChadVKealey Profile Picture
    1,393 on 08 Jan 2021 at 15:22:49
    Re: Compare values using condition

    Well, you don't strictly need to do those things, but it simplifies things a little by replacing one complicated expression with several simpler actions. 

     

    As for why it's complicated, that's because the "Responses" output from the "Start and wait for an approval" or "Wait for an approval" actions is an array. In other words, even if you only assign an approval to one person, the properties of their response are stored as a single-item array. Here is a sample from a test flow I have:

    [
     {
     "responder": {
     "id": "<guid>",
     "displayName": "Last,First",
     "email": "email@domain.com",
     "tenantId": "<tenant-id>",
     "userPrincipalName": "email@domain.com"
     },
     "requestDate": "2021-01-08T15:03:44Z",
     "responseDate": "2021-01-08T15:04:03Z",
     "approverResponse": "Approve",
     "comments": "blah blah blah"
     }
    ]

    Because "comments" is a property within an array, you can't directly reference it within the "int()" expression. That's also why, when you call that property in the "append to variable" (or, you could use a "set variable") action, Power Automate adds an "Apply to each" loop. So, if there are 3 responses to an approval, and you use the "append" action, varComments will include each responder's comments stuck together (if you used "set", it would contain only the last responders comment, since each subsequent iteration of the loop would overwrite the variable's contents). 

     

    Now, don't get me wrong...there are probably a half-dozen other ways to accomplish this same result. That's one of the things that is simultaneously exciting, frustrating and a little frightening about Power Automate. The method/pattern I use is one that I came up with mostly on my own and it's worked well for me, but you might find another way to do it that's easier for you. The key is understanding that the format of the data (e.g.: string, integer, array, object, etc.) impacts how you can use or reference it. In this case, it's not possible to convert an array of strings into a single integer value, so you first need to convert it from an array of strings to a single string; once you have that, you can convert it to an integer. There are a number of good resources out there on handling different types/forms of data in Power Automate. Specific to arrays, I recommend this page: https://sharepains.com/2018/07/10/power-automate-shed-some-light-on-arrays/

     

     

  • SK_Tan Profile Picture
    98 on 08 Jan 2021 at 03:48:07
    Re: Compare values using condition

    Thanks again on your support. It works now!!

     

    Though I still don't understand why we need to add the (1) variables and (2) append to variables to the flow (why can't we just add the comments to the left side of the condition.

  • Verified answer
    ChadVKealey Profile Picture
    1,393 on 07 Jan 2021 at 13:41:44
    Re: Compare values using condition

    When you initialize the variable, leave the Value blank. The Append to string variable action is adding the value in the comments to the original 99000. So, if you enter 99000 in the comments, the variable is going to be 9900099000, which is larger than 100000. 

     

    Alternately, you could use the "Set variable" action (instead of "Append to variable") and the value in the comments will overwrite the original value in the variable.

  • SK_Tan Profile Picture
    98 on 07 Jan 2021 at 08:18:21
    Re: Compare values using condition

    Thanks for your response.

     

    I configured the flow based on your suggestion however it doesn't work accordingly.

     

    e.g. when my comment was 99000 (less than 100000), it should flow to person B instead of person A. The actual result flows to person A. Below is my flow, would you take a look see where it goes wrong:

     

    SK_Tan_3-1610007483781.png

     

    SK_Tan_1-1610007440482.png

    SK_Tan_2-1610007452119.png

     

  • ChadVKealey Profile Picture
    1,393 on 03 Jan 2021 at 17:37:16
    Re: Compare values using condition

    "Responses Comments" is technically an array of strings, because there may be more than one Response to the Approval. What I usually do is initialize a string variable (which you need to do at the "root" level of the flow - not inside of a loop or condition) like "varApprovalComments", then add an "Append to string variable" step to add the Responses Comments to that variable. This will force an "Apply to each" loop, but that's OK, because what you end up with is the contents of the "Responses Comments" array in a single string variable. Then, you reference that in the left side of your condition (int(varApprovalComments)).

     

    I might also suggest - for a bit of error avoidance - that you check the contents of that variable for any non-numeral characters. If, for example, someone throws a comma in there as a separator (e.g.: 1,000), that may cause the int expression to fail (maybe I'm wrong and it'll just ignore separators, but I doubt it). And if someone enters text in the comments, that will definitely cause int to fail. Users are users, someone will put something in there that they shouldn't, no matter how carefully you explain that they shouldn't, so it pays to build in some way to handle that error before it happens. 

  • SK_Tan Profile Picture
    98 on 03 Jan 2021 at 06:29:02
    Re: Compare values using condition

    Thanks for your swift response.

     

    When I applied the int() expression, I couldn't find the dynamic content I want (i.e. Responses Comments from person X). Please see below screenshot. Can you shed some lights?

     

    SK_Tan_0-1609655225756.png

     Thanks and best regards,

    SK

  • ChadVKealey Profile Picture
    1,393 on 03 Jan 2021 at 03:41:24
    Re: Compare values using condition

    Regardless of what the approver types into the comments field, it will be treated as a string, so if you want to compare it to an integer, you need to convert it to an integer value. Try wrapping the dynamic data on the left side of the condition in the int expression (example: int(dynamic-content) )

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,780 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,093 Most Valuable Professional

Leaderboard
Loading started