# Async JS setting a variable

**URL:** <https://community.weweb.io/t/async-js-setting-a-variable/7332>\
**Category:** How do I?\
**Created:** [February 28, 2024, 11:59pm UTC](https://community.weweb.io/t/async-js-setting-a-variable/7332 "2024-02-28T23:59:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam1](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/sam1/32/6724_2.png) [@sam1](https://community.weweb.io/u/sam1)\
**Post date:** [February 28, 2024, 11:59pm UTC](https://community.weweb.io/t/async-js-setting-a-variable/7332/1 "2024-02-28T23:59:52Z")

</div>

Hello can anyone help with how weweb handles async functions. I am tying to set a variable with an async function like this;

```auto
async function functionName() {
    return 'test';
};

return await functionName();

```

but its not returning anything, how can I achieve this?

---

<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:** [February 29, 2024, 7:25am UTC](https://community.weweb.io/t/async-js-setting-a-variable/7332/2 "2024-02-29T07:25:31Z")

</div>

is this code in a formula, a bound value or a js action?  
for sure you can use async functions in a js action (it’s basically an async action itself).

---

<div class="post-metadata">

**Author:** ![sam1](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/sam1/32/6724_2.png) [@sam1](https://community.weweb.io/u/sam1)\
**Post date:** [February 29, 2024, 8:00pm UTC](https://community.weweb.io/t/async-js-setting-a-variable/7332/3 "2024-02-29T20:00:10Z")

</div>

This is in a change a variable action in a workflow. The full problem is I want to return a base64 string of a pdf file that I have generated on the page so that I can email it and the pdf generation is async, and I want to return what was generated.

---

<div class="post-metadata">

**Author:** ![raydeck](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/raydeck/32/384_2.png) [@raydeck](https://community.weweb.io/u/raydeck)\
**Post date:** [February 29, 2024, 10:44pm UTC](https://community.weweb.io/t/async-js-setting-a-variable/7332/4 "2024-02-29T22:44:01Z")

</div>

To get a bit more help, try zooming out a bit with the context. A video lets you do this much more quickly, because instead of picking “the right screenshot” you let the viewer play and freeze where its most helpful.

Update: Seems like @dorilama took care of you in this round!

---

<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:** [February 29, 2024, 11:03pm UTC](https://community.weweb.io/t/async-js-setting-a-variable/7332/5 "2024-02-29T23:03:33Z")

</div>

the right place for async code is js actions in workflows, everywhere else it doesn’t work as you would expect.  
to solve this add a js action before the change variable action, execute your async logic and return the data (remember to await async operations). then in the change variable action use the “result of step” of the js action.
