How Do You Say "If This Array Contain This Value"?

I have the following in a server action:

$value - the id of an item e.g. 123
response - a comma separated list of ids, e.g. 120,123,125

I want to create a condition in a server action which says this:

If $value is one of the values in response

Does anyone know the code to do that?

Thanks!
Antony.

I don’t think that you need to code anything. Wappler makes it as easy as.

This is the code that Wappler has produced:

<dmx-value id="var1" dmx-bind:value="'25,36,47,58'"></dmx-value>
<div class="container mt-4">
    <div class="row">
        <div class="col">
            <p dmx-hide="var1.value.contains(28)">28 is not included</p>
            <p dmx-show="var1.value.contains(36)">36 is included</p>
        </div>
    </div>
</div>

Use the ‘IN’ condition in your query.

Hi folks…

Thanks for your responses!

But…

I am within a repeat in a server action, so neither of those two options will work!

Antony, as usual i will ask you to:

Show the exact code OR a screenshot of the server action steps you are trying to use. Your abstract descriptions never help us understand what are you doing…

This is totally not clear and not helping us to understand what are you doing:

Hey,

So I was trying Ben’s solution but with a dynamic list of comma separated numbers instead, so my variable looks something like this:
<dmx-value id="varPerm" dmx-bind:value="'{{sc_userRole.data.m}}'"></dmx-value>

And the variable is returning the correct list of numbers when checked on the console:
image

However the condition which I have is not working as it should:

<script is="dmx-flow" id="flow1" type="text/dmx-flow" autorun="autorun">{

  condition: {
    if: "{{varPerm.value.contains(2)}}",
    then: {
      steps: {
        run: {action: "{{browser1.goto('page1')}}", name: "redirect"}
      }
    }
  }
}</script>

Can anyone tell me whats going wrong?

The value being set in varPerm is actually a string and not an array.
You should create an array component, and not variable to get correct options in pickers.
And the dynamic value should be set as:

<dmx-value id="varPerm" dmx-bind:value="sc_userRole.data.m"></dmx-value>