MuleSoft has recently launched Mule 4 which is really powerful especially when MuleSoft decided to use DataWeave as the main expression language. Recently, I was working on upgrading one of our project with Mule 4 and I had to implement “not-contains” condition.
Hmm.. this was tricky as some of the things that I tried did not really work; but at the end solution was really simple. Here is what I tried:
Description | Example | Result |
---|---|---|
Using "not" operator | <when expression="#[not(vars.somestring contains 'abc')]"> ... </when> | Not Working |
Using "!" operator | <when expression="#[!(vars.somestring contains 'abc')]"> ... </when> | Not Working |
Using "if-else" | <when expression="#[if(vars.somestring contains 'abc') false else true]"> ... </when> | Working! |
As you see, third implementation works perfectly. We can enhance “if” condition to add more conditions as needed.