# Components don't encapsulate variables

**URL:** <https://forum.knime.com/t/components-dont-encapsulate-variables/31816>\
**Category:** KNIME Analytics Platform\
**Tags:** flow-variables\
**Created:** [March 29, 2021, 5:01pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816 "2021-03-29T17:01:20Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![berti093](https://forum-cdn.knime.com/user_avatar/forum.knime.com/berti093/32/61891_2.png) [@berti093](https://forum.knime.com/u/berti093)\
**Post date:** [March 29, 2021, 5:01pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/1 "2021-03-29T17:01:20Z")

</div>

Hi!

In my understanding a component should let through just the selected variables. For me it’s not working (let through all variables, actually my original variable live in the ‘component after’ node /regarding the owner ID/). It’s worked in the past (before the 4.3 update). Could someone help me in this topic?

Atteched a sample workflow and the print screen of it.

Thank You very much.

![image](https://forum-cdn.knime.com/uploads/default/original/3X/6/c/6cc98e0fc224b97547cefb92daba0403d37e3722.png)

[Variable\_Error.knwf](https://forum.knime.com/uploads/short-url/iKTlXsiY9lMWGxgfWdhXVIFnwXe.knwf) (34.3 KB)

---

<div class="post-metadata">

**Author:** ![sjporter](https://forum-cdn.knime.com/user_avatar/forum.knime.com/sjporter/32/33442_2.png) [@sjporter](https://forum.knime.com/u/sjporter)\
**Post date:** [March 29, 2021, 6:27pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/2 "2021-03-29T18:27:47Z")

</div>

Hey @berti093,

If I understand correctly, you’re looking to have variables available inside a component and/or passed through to following nodes.

In that case, open up the component and configure the Component Input and Component Output. They will let you select the variables that are passed in and out of the component.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/9/1/910a183e7e99475e658a6dd85d7da7686cbe180a.png)

Cheers,

@sjporter

---

<div class="post-metadata">

**Author:** ![bruno29a](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bruno29a/32/28802_2.png) [@bruno29a](https://forum.knime.com/u/bruno29a)\
**Post date:** [March 29, 2021, 6:35pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/3 "2021-03-29T18:35:43Z")

</div>

Hi @berti093 , it looks like the component has control only on what’s happening inside the component.  
Here’s an example/test from your workflow. I modified the value of Variable from “variable” to “New Value”:  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/6/b/6b2933f268728819e48b284a616820949cc8f2fd.png)

And also allow the variables through, we can see the new value for the variable as output from the component:  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/2/0/2009084994b9189452efa9fa2e04633e24a745c6.png)

I keep the same change in value (“New Value”), but this time I exclude the variable from the component:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/6/5/65fc7ee0e7a665133259f63eee36db8356a0964e.png)  
and the original value that was outside the Component is restored. It’s using the “global” (“global” from the point of the view of the Component) value instead:  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/f/6/f60d17420a745567ad7a5734f5112d4bdd0960da.png)

I don’t think you can “remove” flow variables.

---

<div class="post-metadata">

**Author:** ![berti093](https://forum-cdn.knime.com/user_avatar/forum.knime.com/berti093/32/61891_2.png) [@berti093](https://forum.knime.com/u/berti093)\
**Post date:** [March 29, 2021, 6:36pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/4 "2021-03-29T18:36:19Z")

</div>

Hi @sjporter ,

What I would like is the opposite: If I have a lot of variables I want the component to limit which variable goes through and which is not (I configure the input and the output accordingly).

I configured my component input and output (I think correctly), but I cannot achive the ‘component after’ to have no variable.

Thank You for Your help!

Best regards,  
Bertold

---

<div class="post-metadata">

**Author:** ![bruno29a](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bruno29a/32/28802_2.png) [@bruno29a](https://forum.knime.com/u/bruno29a)\
**Post date:** [March 29, 2021, 6:36pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/5 "2021-03-29T18:36:25Z")

</div>

hi @sjporter , he’s trying NOT to pass the variable 🙂

---

<div class="post-metadata">

**Author:** ![berti093](https://forum-cdn.knime.com/user_avatar/forum.knime.com/berti093/32/61891_2.png) [@berti093](https://forum.knime.com/u/berti093)\
**Post date:** [March 29, 2021, 6:43pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/6 "2021-03-29T18:43:13Z")

</div>

Dear @bruno29a ,

Thank You for the detailed explanation. When a workflow is big, it can be pretty messy with many variables, it would be good to manage them.

I remembered so that components can do that, but I was wrong then ☹

Best regards,  
Bertold

---

<div class="post-metadata">

**Author:** ![sjporter](https://forum-cdn.knime.com/user_avatar/forum.knime.com/sjporter/32/33442_2.png) [@sjporter](https://forum.knime.com/u/sjporter)\
**Post date:** [March 29, 2021, 6:56pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/7 "2021-03-29T18:56:13Z")

</div>

Hey @berti093,

You can prevent variables from exiting a component if they were defined within the component itself, but I don’t believe you can prevent a variable that is defined outside of the component from passing through the component.

Cheers,

@sjporter

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [March 30, 2021, 7:36pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/8 "2021-03-30T19:36:22Z")

</div>

Sometimes a flow variable filter would come in handy, although I can see that might further complicate some workflows.

---

<div class="post-metadata">

**Author:** ![Daniel\_Weikert](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/d/e47c2d/32.png) [@Daniel\_Weikert](https://forum.knime.com/u/Daniel_Weikert)\
**Post date:** [March 31, 2021, 5:27pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/9 "2021-03-31T17:27:49Z")

</div>

You could still write your variables to table row, filter them and write them back to variable right?

---

<div class="post-metadata">

**Author:** ![sjporter](https://forum-cdn.knime.com/user_avatar/forum.knime.com/sjporter/32/33442_2.png) [@sjporter](https://forum.knime.com/u/sjporter)\
**Post date:** [March 31, 2021, 6:27pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/10 "2021-03-31T18:27:11Z")

</div>

> write your variables to table row, filter them and write them back to variable

@Daniel_Weikert Great thinking; that’s a simple & elegant solution. I might look into making a related component…

---

<div class="post-metadata">

**Author:** ![bruno29a](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bruno29a/32/28802_2.png) [@bruno29a](https://forum.knime.com/u/bruno29a)\
**Post date:** [March 31, 2021, 8:59pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/11 "2021-03-31T20:59:03Z")

</div>

Hi @sjporter and @Daniel_Weikert , I am not sure I understand how writing variables to table row, filter them and write them back to variable removes / filters variables…

When writing variables to table row, the variables still exist. So no matter what operations are done after, these variables are not going away.

Am I missing something? 🙂

---

<div class="post-metadata">

**Author:** ![sjporter](https://forum-cdn.knime.com/user_avatar/forum.knime.com/sjporter/32/33442_2.png) [@sjporter](https://forum.knime.com/u/sjporter)\
**Post date:** [March 31, 2021, 9:17pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/12 "2021-03-31T21:17:32Z")

</div>

Hey @bruno29a,

I tried making a component for this and saw the same behavior. I’m going to ask around internally and see if anyone else has tried to filter variables out of a workflow in the manner you’re describing.

May I ask, what’s the reason for wanting to filter the variables out? As in, what’s the use case?

Cheers,

@sjporter

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [April 1, 2021, 5:33am UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/13 "2021-04-01T05:33:51Z")

</div>

@sjporter in complex workflows where you use several metanodes or components you might use the same flow variable but the content might have changed. And then the first flow variable filled would get chosen.

So it could make sense to filter the variables or in some ways prioritize them. Or empty or delete them - like in programming languages.

I would assign individual names to flow variables to control which ones are used but I could see a case for filtering them. Not having though thru all the implications.

---

<div class="post-metadata">

**Author:** ![berti093](https://forum-cdn.knime.com/user_avatar/forum.knime.com/berti093/32/61891_2.png) [@berti093](https://forum.knime.com/u/berti093)\
**Post date:** [April 3, 2021, 1:39pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/14 "2021-04-03T13:39:59Z")

</div>

Thank You for the help. My problem or use case is the same as @mlauber71 : Messy workflows and taken variable names. (As I understand @mlauber71 's case)

---

<div class="post-metadata">

**Author:** ![sjporter](https://forum-cdn.knime.com/user_avatar/forum.knime.com/sjporter/32/33442_2.png) [@sjporter](https://forum.knime.com/u/sjporter)\
**Post date:** [April 5, 2021, 1:45pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/15 "2021-04-05T13:45:19Z")

</div>

Hey @berti093 / @mlauber71,

I received confirmation from the dev team that it’s not possible to remove flow variables from a workflow today. I submitted a new node idea in JIRA for this.

My recommendation for the workflow you shared in the original post would be to feed the table row into the component before converting it to a variable so that you can keep the scope of the variable within the component.

Cheers,

@sjporter

---

<div class="post-metadata">

**Author:** ![berti093](https://forum-cdn.knime.com/user_avatar/forum.knime.com/berti093/32/61891_2.png) [@berti093](https://forum.knime.com/u/berti093)\
**Post date:** [April 5, 2021, 7:23pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/16 "2021-04-05T19:23:26Z")

</div>

Dear @sjporter ,

Thank You!

BR  
Bertold

---

<div class="post-metadata">

**Author:** ![bruno29a](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bruno29a/32/28802_2.png) [@bruno29a](https://forum.knime.com/u/bruno29a)\
**Post date:** [April 10, 2021, 2:14am UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/17 "2021-04-10T02:14:58Z")

</div>

It’s almost never that I face the need to “clean up” variables on my side. Most of my workflows are built using multiple re-usable components (shared components that I built since using Knime), so I have full control on these variables - I only return any variables that are needed per component. Any other variables that are left are basically for the usability of the workflow itself.  
So, I usually do not have any unnecessary variables around.

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [October 9, 2021, 2:15pm UTC](https://forum.knime.com/t/components-dont-encapsulate-variables/31816/18 "2021-10-09T14:15:55Z")

</div>

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