Action button to add new column

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.

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

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://mini-developer.work/insert-or-add-a-column/

I hope it works.

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

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

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

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

Link to app: https://silowy.glideapp.io/ → Trening 3 tab

1 Like

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.

1 Like