# Trigger a javascript function from a custom action in Glide

**URL:** <https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660>\
**Category:** Ask for Help\
**Created:** [February 8, 2023, 1:18pm UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660 "2023-02-08T13:18:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![elombat](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/elombat/32/54033_2.png) [@elombat](https://community.glideapps.com/u/elombat)\
**Post date:** [February 8, 2023, 1:18pm UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/1 "2023-02-08T13:18:27Z")

</div>

Hi Gliders, Happy new year and best wishes to you all. I’m opening this thread because I’m looking for a way to trigger a JS function from the custom ‘actions’ in Glide. Is it something that is possible? If so, can someone indicate how this can be done?

I simply want to be able to send a GET or a POST via JS when a button is pressed for ex…

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [February 9, 2023, 12:08am UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/3 "2023-02-09T00:08:47Z")

</div>

What does your JS function do? Do you expect to get back a result value inside Glide?

---

<div class="post-metadata">

**Author:** ![elombat](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/elombat/32/54033_2.png) [@elombat](https://community.glideapps.com/u/elombat)\
**Post date:** [February 9, 2023, 8:04am UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/4 "2023-02-09T08:04:45Z")

</div>

Hi @ThinhDinh , My JS function is just sending some variable via Get to an IP address in my local network. No, I don’t need to get any result back. I’m sending a Get to a Thermal printer with the content of what I’m printing and instructions to feed and cut paper. I noticed that it’s how this is done when using the “test page” on the Thermal printer’s interface, so that’s a shortcut I use and it’s very handy. I use the “Generate URL” column, and I have what I want when I use the “open link” action, but I don’t want to open a new window or tab everytime I print, that’s why I was hoping I can use JS instead.

Thanks a lot in advance for your time.

---

<div class="post-metadata">

**Author:** ![elombat](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/elombat/32/54033_2.png) [@elombat](https://community.glideapps.com/u/elombat)\
**Post date:** [March 3, 2023, 2:44pm UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/5 "2023-03-03T14:44:52Z")

</div>

Hi @ThinhDinh, any idea since last time ?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [March 3, 2023, 4:48pm UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/6 "2023-03-03T16:48:00Z")

</div>

Hola,

Try with this to start:

> [@Fetch json with token](https://community.glideapps.com/t/fetch-json-with-token/53097/7):
>
> Hola! I think it’s possible but if you share your cURL command (or Fetch syntax) we can try to fix it. Your JS code might look like: var data= await fetch('YOUR\_URL', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'YOUR\_BearerToken' }, }); const json = await data.text(); // or data.json(); return json Saludos!

Saludos!

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [March 4, 2023, 12:39am UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/7 "2023-03-04T00:39:02Z")

</div>

Is there a way to control this? Like does it keep sending requests or can you actually trigger it with a user action?

---

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [March 4, 2023, 12:06pm UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/8 "2023-03-04T12:06:58Z")

</div>

Sure,

Just create an additional conditional sentence (If - then) to control the execution code:

```auto
let myTrigger = p1; // p1 is the 1st parameter
if (myTrigger == True) {
    var data= await fetch('YOUR_URL', {
       method: 'POST',
        headers: {
           'Content-Type': 'application/x-www-form-urlencoded',
           'Authorization': 'YOUR_BearerToken'
        },
    });
    const json = await data.text(); // or data.json();   
    return json
  }

```

Now, you can create a custom action using the new [Wait Action feature](https://community.glideapps.com/t/wait-action/23794/54) to get it:

1. Set **True** to code’s trigger (“myTrigger” as parameter/column)
2. Wait 2-3 sec to allow the JS to run
3. Set **False** to code’s trigger to disable next executions

Saludos!

---

<div class="post-metadata">

**Author:** ![slscustom.ru](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/slscustom.ru/32/77336_2.png) [@slscustom.ru](https://community.glideapps.com/u/slscustom.ru)\
**Post date:** [March 4, 2023, 12:50pm UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/9 "2023-03-04T12:50:33Z")

</div>

Hi! Thanks for sharing!  
Using this method can we trigger Google App Scriprt and recive result from GScript? Right?

---

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [March 4, 2023, 1:04pm UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/10 "2023-03-04T13:04:16Z")

</div>

Of course, I have done this before and works fine!

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [March 5, 2023, 12:02am UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/11 "2023-03-05T00:02:20Z")

</div>

I assume Glide only does a call again when the myTrigger column changes? For paid API services I don’t want that to be refreshed every 10 seconds.

---

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [March 5, 2023, 5:26pm UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/12 "2023-03-05T17:26:00Z")

</div>

> [@ThinhDinh](#):
>
> For paid API services I don’t want that to be refreshed every 10 seconds.

Hola Thinh,

Sorry, I couldn’t follow you about this concern. If you give me more details I will appreciate it.

Gracias!

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [March 6, 2023, 12:18am UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/13 "2023-03-06T00:18:12Z")

</div>

I mean does Glide store the cache of the result and don’t initiate any more calls until one of the inputs are changed? I don’t want to be charged for a lot of calls to a paid service just to receive the same result.

Furthermore, if X people login to the app, does it mean X calls times the number of rows you have?

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [March 6, 2023, 1:22am UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/14 "2023-03-06T01:22:49Z")

</div>

Based on some recent experimentation, the way I understand it, a javascript column is called (for all rows) when the app is initially loaded. After that, it’s called only when an input parameter changes in that particular row. Then multiply that by the number of users, since it runs locally.

So unlike a back end server, which can run something once and cache it, you will definitely have more frequent calls since the local device is doing the calling, and multiple users can be calling the code. But once an app is running, the javascript won’t run again unless an input parameter changes.

---

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [March 6, 2023, 1:24am UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/15 "2023-03-06T01:24:00Z")

</div>

Interesting. Thanks for investigating @Jeff_Hager!

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [March 6, 2023, 1:30am UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/16 "2023-03-06T01:30:51Z")

</div>

Thanks a lot Jeff!

---

<div class="post-metadata">

**Author:** ![elombat](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/elombat/32/54033_2.png) [@elombat](https://community.glideapps.com/u/elombat)\
**Post date:** [March 6, 2023, 7:43am UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/17 "2023-03-06T07:43:58Z")

</div>

This is brilliant, thanks a lot @gvalero

---

<div class="post-metadata">

**Author:** ![slscustom.ru](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/slscustom.ru/32/77336_2.png) [@slscustom.ru](https://community.glideapps.com/u/slscustom.ru)\
**Post date:** [April 8, 2023, 11:12pm UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/18 "2023-04-08T23:12:39Z")

</div>

Thanks, gvaleo!  
This tricks works perfect!  
Just fined is: from Glide editor it triggs twice but from browser app all ok.

Im trying to trigg some hook and to recive response:  
Updated code

```auto
let myTrigger = p1;
if (myTrigger == true) {
  const url = `https://vektor-systems.bitrix24.ru/rest/13/4825o4an22hrm2o4/crm.contact.list.json?FILTER%5BPHONE%5D=79605463333&SELECT%5BID%5D=`;
  const data = await fetch(url);
  const json = await data.json();   
  return json;
}

```

But filed to fetch  
Im checking processed url and it works from browser but from Glide - not  
Does somebody have ideas?  
Thanks!  
Upd:  
I tried use this three step logic:

1. Set url
2. wait for response
3. Clear url and save response  
with Glide Fetch column and it works perfect. But interesting why it not worked in code column

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [April 9, 2023, 9:05am UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/19 "2023-04-09T09:05:16Z")

</div>

You have to refresh trigger

---

<div class="post-metadata">

**Author:** ![slscustom.ru](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/slscustom.ru/32/77336_2.png) [@slscustom.ru](https://community.glideapps.com/u/slscustom.ru)\
**Post date:** [April 9, 2023, 9:09am UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/20 "2023-04-09T09:09:33Z")

</div>

Hi, Uzo!  
Thanks for response!  
Trigger function worked property and nook has recieved trigg, but in code column i cant recieve responce, but when i tried glide fetch column with the same url it recieving response normaly

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [April 9, 2023, 9:13am UTC](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660/21 "2023-04-09T09:13:44Z")

</div>

Why do you have two await? Fetch first, then use another column to parse the JSON

[Next page](https://community.glideapps.com/t/trigger-a-javascript-function-from-a-custom-action-in-glide/57660.md?page=2)
