Hi everyone!!
Hope can help me, with my problem.
I want to know how I can evaluate an variable to know if is numeric, but I can´t resolve.
I read about the function isnumeric but is not avaible on Microsoft Flow :(.
And I don´t know how resolve this, somebody can give me another way, how I can do this?
Drawing on the other solutions here, this is a solution that worked for my instance.
This is a clever solution @ChristianAbata . Gave me a quick answer to what I needed. Thanks!
For others considering all the various answers here, FWIW, if I am understanding correctly what ChristianAbata is describing with his array-contains method, I would point out that:
1) This will only work if the variable being examined is a single character. If not, you'll want to use substring() to return the character in the string you want to check (assuming the string variable has more than one character). If you need to check a multi-character variable, probably best to use the more elegant answers from @ScottMoore , @Nixar or @v-alzhan-msft
2) This array-of-digits method can be reduced to an expression that can be directly used as the condition in an IF action. You don't have to check the first character, but you have to pick the one character you will examine...and it must exist otherwise substring errors if the string is too short. E.g.:
contains(
split('0_1_2_3_4_5_6_7_8_9_', '_')
, substring(
variables('MyVarToCheckFirstCharacterOfForIsNumeric')
, 0
, 1
)
)
We can also put Compose action that has int() function inside of Scope like Try block and have the branch where it fails inside another Scope(Catch Block). Doing so I find that the flow doesnot results in Failed.
Here I have to convert Date from excel to SharePoint Date and so was checking if the date field from excel is numeric or not.
So, Compose action where I have Convert to Int Function is successful than I will convert that number to Date. If it fails then the flow action will come out of the Scope (Try) and goes to another Scope (Catch). Also Scope (Catch) should be configure to Run after When Scope (Try) fails.
Here is overall diagram of the Flow Action
Amazing that there isn't an isNum or isText available, however, the xpath solution here seems like it would do exactly what I want it to do. Really fancy by the way! Is there a way to update this to work inside an apply to each loop? I initialized a variable at the top, and then inside the loop I tried to "Set Variable" as follows. In fact, I cannot get this to work at all. Simply trying to do data error correction when a user puts in a text comment when all I want is a number. I believe the bottom example is the correct syntax, but I put the top one in there to show where I was heading.
If(equals(xpath(xml(json('{items('Apply_to_each')?['Num']}')), 'number(*/text())'),0),'TRUE','FALSE')
xpath(xml(json('{value:"items('Apply_to_each')?['Num']"}')),'number(*/text())')
The xpath shown here will convert your string value to a float
xpath(xml(json('{value:"99"}')),'number(*/text())')
The above will return a float for 99
xpath(xml(json('{value:"hello world"}')),'number(*/text())')
The above will return a float for NaN
If NaN is returned, a conditional evaluation such as the one shown below, will not error and would return false
Here it is being used with a variable named office...easier for copy & paste in case I end up back here myself 🙂
xpath(xml(json(concat('{value:"',variables('office'),'"}'))),'number(*/text())')
Hi @FlorC ,
You could refer to screenshot below to create the flow:
You should save the variable in a Compose.
The expression in the Comoose 2 as below:
int(outputs('Compose'))
The Compose 4 action would run after the Compose 2 has run failed:
So if the variable is numeric, the Compose 3 would run, if the variable isn't variable, the Compose 4 would run.
You could add send email action under the Compose 3 and Compose4 with the result.
Best regards,
Alice
Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
hi @FlorC what you can to enshure a numeric value is use the expresion int() and inside your number. or you can create an array with numbers to see if your output contains numbers inside.
WarrenBelz
146,745
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,091
Most Valuable Professional