# Action button to add new column

**URL:** <https://community.glideapps.com/t/action-button-to-add-new-column/22898>\
**Category:** Ask for Help\
**Created:** [February 16, 2021, 10:13pm UTC](https://community.glideapps.com/t/action-button-to-add-new-column/22898 "2021-02-16T22:13:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkukulka](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mkukulka/32/21747_2.png) [@mkukulka](https://community.glideapps.com/u/mkukulka)\
**Post date:** [February 16, 2021, 10:13pm UTC](https://community.glideapps.com/t/action-button-to-add-new-column/22898/1 "2021-02-16T22:13:47Z")

</div>

Hi,

I added a button to my project. I need an action for the button to duplicate column K to L, L to M and so on.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/a/7aa9dde2b9228c1f0a4f7d323f67c96c7ef6d9c7.png)

---

<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 16, 2021, 11:16pm UTC](https://community.glideapps.com/t/action-button-to-add-new-column/22898/2 "2021-02-16T23:16:16Z")

</div>

I assume you want the column name to be dynamically inserted as well. What’s your use case here?

---

<div class="post-metadata">

**Author:** ![mrnmkmn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mrnmkmn/32/21743_2.png) [@mrnmkmn](https://community.glideapps.com/u/mrnmkmn)\
**Post date:** [February 17, 2021, 6:01am UTC](https://community.glideapps.com/t/action-button-to-add-new-column/22898/3 "2021-02-17T06:01:35Z")

</div>

Hi mkukulka,

How about setting up a GAS on the spreadsheet side and running it from a button in the app?

Specifically…

**Setup on the spreadsheet side**

- In either a “stand alone” or bound Apps Script file add a `doGet(e)` function.
- Write the code of adding a new column to that function.
- Publish the Apps Script file as a Web App.
- Get the published URL of the Web App.

**Settings on the app side (Glide)**

- Set that published URL to the button

The following are reference websites.  
[https://stackoverflow.com/questions/30126787/call-a-custom-gas-function-from-external-url](https://stackoverflow.com/questions/30126787/call-a-custom-gas-function-from-external-url)  
[https://mini-developer.work/insert-or-add-a-column/](https://mini-developer.work/insert-or-add-a-column/)

I hope it works.

---

<div class="post-metadata">

**Author:** ![mkukulka](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mkukulka/32/21747_2.png) [@mkukulka](https://community.glideapps.com/u/mkukulka)\
**Post date:** [February 17, 2021, 7:30pm UTC](https://community.glideapps.com/t/action-button-to-add-new-column/22898/4 "2021-02-17T19:30:27Z")

</div>

@ThinhDinh yes I want column name to be copied as well.

@mrnmkmn uhh… there is nothing less complicated? 😉 I am not good at developing.

---

<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 18, 2021, 12:07am UTC](https://community.glideapps.com/t/action-button-to-add-new-column/22898/5 "2021-02-18T00:07:34Z")

</div>

Scripts, as @mrnmkmn pointed out is your best bet. As of now we can only add new rows from an app, not columns.

---

<div class="post-metadata">

**Author:** ![mkukulka](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mkukulka/32/21747_2.png) [@mkukulka](https://community.glideapps.com/u/mkukulka)\
**Post date:** [March 4, 2021, 9:25pm UTC](https://community.glideapps.com/t/action-button-to-add-new-column/22898/6 "2021-03-04T21:25:51Z")

</div>

Hi guys.

OK, I got the script

```
function doGet() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getActiveSheet();
  var col = sh.getLastColumn();
  var colContents = sh.getRange(1, col).getValue();
  var previousHeaderNum = colContents.toString().replace(/\D/g, '');
  var headerNum = (parseInt(previousHeaderNum, 10) +1);
  var header = "Obciązenie " + headerNum + " tyg."

  sh.insertColumnAfter(col);
  sh.getRange(1, col+1).setValue(header);

}

```

When I run the script from [script.google.com](http://script.google.com) it runs OK. Bur how to set a button on GlideApp to run the script to get next column on spreadsheet and next row in app? I tried to use it with webhook but it is not workin.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/2/6/26bed63dc6f57ed0ccbaffb8c5553e0c804a27cd.png)

Link to app: [https://silowy.glideapp.io/](https://silowy.glideapp.io/) → Trening 3 tab

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [March 5, 2021, 4:17am UTC](https://community.glideapps.com/t/action-button-to-add-new-column/22898/7 "2021-03-05T04:17:57Z")

</div>

> [@mkukulka](#):
>
> When I run the script from [script.google.com](http://script.google.com) it runs OK. Bur how to set a button on GlideApp to run the script to get next column on spreadsheet and next row in app? I tried to use it with webhook but it is not workin.

You can use Glide to change a value in your spreadsheet (anywhere), and then detect that change with an onChange() trigger. That trigger can then fire your script. I demonstrated this technique in my [Apps Script JSON API tutorial](https://community.glideapps.com/t/using-app-script-with-a-json-api/20051).
