Intermediate variable in FEEL expression -- how?

Hello,

in the DMN I’m now working on, I have a string variable as an input (say, the var name is name). Now I want to have an intermediate rule to compute a boolean value (say, isMale).

The computation can be schematically expressed as the following script:

tmp = upper case(name)
isMale = (tmp = "JOHN" or tmp = "MICHAEL")

My problem is that the computation of “isMale” should be one FEEL expression. Hence, as of now, I write

isMale = (upper case(name) = "JOHN" or upper case(name) = "MICHAEL")

I don’t like the fact that I have to repeat the expression upper case(name).

Is it possible to somehow define it as an intermediate variable?

IMO I need something similar to the LET function in Excel. Using it, my expression would look like

isMale = let(tmp = upper case(name), tmp = "JOHN" or tmp = "MICHAEL")

Is this (or something similar) possible in FEEL?

Thank you for any hints.

Hi @fml2

Maybe something like below can serve your needs

some item in ["JOHN", "MICHAEL"] satisfies item = upper case(name)

2 Likes

Thank you @hassang for the idea! This would indeed be a solution if my case wasn’t a little bit more complicated in reality (I’d need several checks with “upper case (name)”) :slight_smile:

But I’ve learned something new and useful. You solution effectively inverts the order of assignments: you first create the set of possible values and the perform some code upon them. Cool.

Is the opposite also possible (first assign value, then work with it)?

@fml2 - you can also do something like this:

={
  upperName: upper case(name),
  isMale: upperName = "JOHN" or upperName = "MICHAEL"
}.isMale
3 Likes

Thank you @nathan.loding ! This is exactly what I’ve been looking for! A very cool technique!

@hassang , I’ve changed the solution mark just so that the information on the forum is as correct as possible. I’m still very grateful to you for your reply!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.