# 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:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MatthewS](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/matthews/32/3582_2.png) [@MatthewS](https://community.weweb.io/u/MatthewS)\
**Post date:** [March 13, 2024, 4:53pm UTC](https://community.weweb.io/t/setting-component-variable-using-js/7563/1 "2024-03-13T16:53:04Z")

</div>

Hey Hey 👋,

As the title says, it is possible to change the value of a component variable using JS?  
I am currently trying to change a value and keep getting the error ‘Invalid left-hand side in assignment’

Example JS I am trying:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/c/ccd84349ee844204f49971539254f3f7bfaaaf17.png)

Thanks!

---

<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, 6:14pm UTC](https://community.weweb.io/t/setting-component-variable-using-js/7563/2 "2024-03-13T18:14:08Z")

</div>

> [@MatthewS](#):
>
> I am currently trying to change a value and keep getting the error ‘Invalid left-hand side in assignment’

> **[SyntaxError: invalid assignment left-hand side - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_assignment_left-hand_side#using_optional_chaining_as_assignment_target)**
>
> The JavaScript exception "invalid assignment left-hand side" occurs when there was an unexpected assignment somewhere. It may be triggered when a single = sign was used instead of == or ===.

---

<div class="post-metadata">

**Author:** ![MatthewS](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/matthews/32/3582_2.png) [@MatthewS](https://community.weweb.io/u/MatthewS)\
**Post date:** [March 13, 2024, 7:16pm UTC](https://community.weweb.io/t/setting-component-variable-using-js/7563/3 "2024-03-13T19:16:02Z")

</div>

Thanks - although this is the error it doesn’t make sense what is causing it, as using the exact same code in the example on a non-component variable works fine.

Obviously this relates to how component variables are operating behind the scenes, just not sure if there is a workaround.

---

<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.

---

<div class="post-metadata">

**Author:** ![MatthewS](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/matthews/32/3582_2.png) [@MatthewS](https://community.weweb.io/u/MatthewS)\
**Post date:** [March 14, 2024, 1:55pm UTC](https://community.weweb.io/t/setting-component-variable-using-js/7563/5 "2024-03-14T13:55:49Z")

</div>

Perfect! Thank you.  
The method @aurelie gave in the thread did the job.

For anyone who may have this in the future, changing the example code to the following resolved the issue:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/e/e001fb3917a4cc1ca3f7698b7f932e4bec6d796a.png)

---

<div class="post-metadata">

**Author:** ![aurelie](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/aurelie/32/13249_2.png) [@aurelie](https://community.weweb.io/u/aurelie)\
**Post date:** [March 14, 2024, 5:56pm UTC](https://community.weweb.io/t/setting-component-variable-using-js/7563/6 "2024-03-14T17:56:42Z")

</div>

Glad you find the solution 🙂  
Using component local features is still undocumented as it is pretty new (for direct call in js)  
We will try to update the doc as soon as possible 🙂

---

<div class="post-metadata">

**Author:** ![Cajo](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Cajo](https://community.weweb.io/u/Cajo)\
**Post date:** [October 21, 2025, 6:59am UTC](https://community.weweb.io/t/setting-component-variable-using-js/7563/7 "2025-10-21T06:59:18Z")

</div>

Hi! Just wondering if the documentation for setting component variables now exists?
