# All instructions in a condition are executed

**URL:** <https://community.weweb.io/t/all-instructions-in-a-condition-are-executed/797>\
**Category:** Ask us anything\
**Created:** [July 15, 2022, 12:22pm UTC](https://community.weweb.io/t/all-instructions-in-a-condition-are-executed/797 "2022-07-15T12:22:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bargeo](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/bargeo/32/932_2.png) [@Bargeo](https://community.weweb.io/u/Bargeo)\
**Post date:** [July 15, 2022, 12:22pm UTC](https://community.weweb.io/t/all-instructions-in-a-condition-are-executed/797/1 "2022-07-15T12:22:20Z")

</div>

I am looking to manage the status of buttons that are used to filter data. For that, I have a json configuration file: each time a button is clicked, a condition looks if this filter is already present in the config file. If it is, it removes it, if it is not, it adds it. So I wrote a javascript like this (simplified for a better understanding):  
if(contains(config[filter],context.item[‘filter’]),remove(config[filter],context.item[‘name’],add(config[filter],context.item[‘name’])).

But this does not work normally: both operations (add and remove) are performed systematically. I can see this simply by changing the “remove” to an “add”, in which case the filter is added twice in the config file.  
It is as if there were no condition, but simply two lines of instructions that are executed.  
I even tried to modify the condition such as: if(true==false,…). Even in this case, the two instructions in the condition are executed!

---

<div class="post-metadata">

**Author:** ![kevinwasie](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/kevinwasie/32/402_2.png) [@kevinwasie](https://community.weweb.io/u/kevinwasie)\
**Post date:** [July 15, 2022, 12:32pm UTC](https://community.weweb.io/t/all-instructions-in-a-condition-are-executed/797/2 "2022-07-15T12:32:07Z")

</div>

Do you have the JavaScript in a workflow?

Can you paste the whole code.

You’re missing a parenthesis on the example for remove. )

---

<div class="post-metadata">

**Author:** ![Bargeo](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/bargeo/32/932_2.png) [@Bargeo](https://community.weweb.io/u/Bargeo)\
**Post date:** [July 15, 2022, 12:38pm UTC](https://community.weweb.io/t/all-instructions-in-a-condition-are-executed/797/3 "2022-07-15T12:38:04Z")

</div>

Yes, javascript is in a “click” workflow.  
Here a video with the bug :  
[https://www.transfernow.net/dl/20220715ZANy7LQF](https://www.transfernow.net/dl/20220715ZANy7LQF)  
Here the code :

```auto
wwFormulas.if(wwFormulas.contains(variables['a57c1775-0fec-4080-9b46-5a21c8ac4c3d'][context.item['parent']['data']['category']],context.item.data['name_en']),
    variables['a57c1775-0fec-4080-9b46-5a21c8ac4c3d'][context.item['parent']['data']['category']] = wwFormulas.add(variables['a57c1775-0fec-4080-9b46-5a21c8ac4c3d'][context.item['parent']['data']['category']], context.item.data['name_en']), variables['a57c1775-0fec-4080-9b46-5a21c8ac4c3d'][context.item['parent']['data']['category']] = wwFormulas.add(variables['a57c1775-0fec-4080-9b46-5a21c8ac4c3d'][context.item['parent']['data']['category']], context.item.data['name_en']));
context.item.data['active'] = !context.item.data['active']

```

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [July 15, 2022, 1:21pm UTC](https://community.weweb.io/t/all-instructions-in-a-condition-are-executed/797/4 "2022-07-15T13:21:18Z")

</div>

`wwFormulas.if` is a function not a `if else` statement. Assignments or other functions in the parameters are all executed.

You should use an `if else` statement.

---

<div class="post-metadata">

**Author:** ![Bargeo](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/bargeo/32/932_2.png) [@Bargeo](https://community.weweb.io/u/Bargeo)\
**Post date:** [July 15, 2022, 2:12pm UTC](https://community.weweb.io/t/all-instructions-in-a-condition-are-executed/797/5 "2022-07-15T14:12:44Z")

</div>

Thanks dorilama ! I thinked wwFormulas.if is same than pure javascript if/else. Then i don’t understand how wwFormulas.if works and what is its utility, but from now, i will use pure javascript when it’s needed.

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [July 15, 2022, 2:26pm UTC](https://community.weweb.io/t/all-instructions-in-a-condition-are-executed/797/6 "2022-07-15T14:26:22Z")

</div>

the utility is if you want to choose between two values with the nocode formula.  
The equivalent of `if else` in nocode workflows will be the new branching feature.

---

<div class="post-metadata">

**Author:** ![kevinwasie](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/kevinwasie/32/402_2.png) [@kevinwasie](https://community.weweb.io/u/kevinwasie)\
**Post date:** [July 15, 2022, 2:35pm UTC](https://community.weweb.io/t/all-instructions-in-a-condition-are-executed/797/7 "2022-07-15T14:35:57Z")

</div>

The noCode if formula is good to use, but you want to use it different than you were.

The wwFormulas if is going to return a value. So, if you want to change a value of a variable in the workflow, for example, it would be good to use the noCode formula.

Or if you want to conditionally display an element … Bind the elements display property and use noCode if formulas like if(contains(roles\_array,“Admin”)), true, false)

The above would return true if the roles\_array contains “Admin”
