# Setting Component Variable using JS

**URL:** <https://community.weweb.io/t/setting-component-variable-using-js/7563>\
**Category:** How do I?\
**Created:** [March 13, 2024, 4:53pm UTC](https://community.weweb.io/t/setting-component-variable-using-js/7563 "2024-03-13T16:53:04Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [March 13, 2024, 8:48pm UTC](https://community.weweb.io/t/setting-component-variable-using-js/7563/4 "2024-03-13T20:48:56Z")

</div>

it works only when the chain returns a variable, but when it returns undefined you get the error. you have indeed the problem of not finding the variable, that is related to components, but the code is prone to errors and refactoring as the example of the link will make it more robust.

this may be helpful:

> [@Within Component, how to get the updateVariable or executeWorkflow IDs, like we do for global Vars and WFs?](https://community.weweb.io/t/within-component-how-to-get-the-updatevariable-or-executeworkflow-ids-like-we-do-for-global-vars-and-wfs/7463/2):
>
> At the moment, there is no easy UX way to have the component variable id, but you can just click on the explorer en JS mode to see it. Please be carefull that the method to call is different for a local variable than for a global variable context.component.methods.updateVariable vs wwLib.wwVariable.updateValue There is no way to call an internal workflow from a javscript code at the moment, but id is available the same way than the global one.

---

_[View the full topic](https://community.weweb.io/t/setting-component-variable-using-js/7563)._
