cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SK_Tan
Helper III
Helper III

Compare values using condition

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

8 REPLIES 8
ChadVKealey
Memorable Member
Memorable Member

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) )

 

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

"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
Helper III
Helper III

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

 

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.

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.

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/

 

 

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

 

Looking ahead more valuable sharing like this.

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (3,129)