0

I have stored a value in a Variable. Its an ID, it looks like this 1-2823596-1 or CAT-R131-L6267. Now I need to write an expression which filters this ID based on the first value of the ID(i.e if it's number or alphabet). According to that I will put my choice router. Can anyone please let me know how to write this expression as I am relatively new to Mulesoft

tried with the given example but did't able to create

enter code here {  a: payload.a match {
case is Object -> 'OBJECT'
case is String -> 'STRING'
case is Number -> 'NUMBER'
case is Boolean -> 'BOOLEAN'
case is Array -> 'ARRAY'
case is Null -> 'NULL'
else -> 'ANOTHER TYPE'  },  b: payload.b match {
case y is Object -> { 'Type': { 'OBJECT' : y} }
case y is String -> { 'Type': { 'STRING' : y} }
case y is Number -> { 'Type': { 'NUMBER' : y} }
case y is Boolean -> { 'Type': { 'BOOLEAN' : y} }
case y is Array -> { 'Type': { 'ARRAY' : y} }
case y is Null -> { 'Type': { 'NULL' : y} }
else -> { 'Type': { 'ANOTHER TYPE' : payload.b} }  }}

Also tried using substring

enter code here #[vars.reqTcpn == vars.reqTcpn[0..0] match[0-9]]

Required to check if the first value of the string is a character or number so that I can put a choice router

1 Answers1

0

You are using Mule 4, so MEL has been replaced with Dataweave as the expression language.

In Mule 4.2 and Dataweave 2.2.0, both recently released, there is a new isNumeric function that does just this:

import isNumeric from dw::core::Strings output application/java --- isNumeric(vars.reqTcpn[0 to 0])

https://docs.mulesoft.com/mule-runtime/4.2/dw-strings-functions-isnumeric

MulE 4 versions < 4.2 you can use a combination of substring[0 to 0] and match for regex to check it's numeric. Then sizeOf to check that there is at least 1 match:

#[sizeOf(match(vars.reqTcpn[0 to 0], '[0-9]')) > 0]
Ryan Carter
  • 11,441
  • 2
  • 20
  • 27