Google Sheets Insert Row Form - google-apps-script

I have a running parts order list that several people use. I am trying to have the top row be a form so the user enters Qty, Part #, and Notes and presses Enter. I want it to add a row to the top of the sheet below the headers and maintain the table structure so we can filter.

Instead of using the top row, go to Tools then create form. This will make it easier to input stuff. Also no one can muck up your sheet.
Also I would read what you can post here :) I like to be friendly so I thought I'd put an answer

You should read about Google Apps Script. GAS is the easiest way to read/write data in Google Spreadsheet/Docs/Forms.
So as far as I understand from your question, you need to insert a row in Google Spreadsheet below the header directly as soon as the forms.
Step 1: Open the spreadsheet using openById(id)
Step 2: Get the worksheet in which you want to save your Google Forms data using getSheetByName(name)
Step 3: Insert row before specified position using insertRowBefore(beforePosition)
So final code should look like this.
var spreadsheet = SpreadsheetApp.openById("1BZuYFCnN_g9vn5crxbPeYlhUKwH6N3u0uT8LCmm-neM");
var sheet = spreadsheet.getSheetByName("Nov-2017");
sheet.insertRowsBefore(2);
The code above will insert only one row below spreadsheet headers. There is an alternative -> insertRowsBefore(beforePosition, howMany) if you want to insert multiple rows at a specified position.
Try this and let me know if you find any difficulties. Hope this is what you're looking for.

Related

Updating Google Sheet with WooCommerce Order

I need to be able to automatically update a google sheet file every time an order is placed through WooCommerce.
I've found the solution below, but using this each individual item ordered is listed as a new row. I'd like the order to be grouped under the order number and the item quantities separated into appropriate columns instead.
https://www.tychesoftwares.com/export-woocommerce-orders-to-google-sheets-in-realtime/
Below is a Google Sheet we are manually updating at present to show you what i mean.
Example
Is there a way to send the WooCommerce orders directly through to Google Sheets in this format?
Thanks so much in advance for any advice!
Yes it looks possible.
I know nothing about WooCommerce, but I believe you can sort out the received data in any way you want.
Look, the last line in their script appends the received data as a new row:
sheet.appendRow([timestamp,order_number,order_created,order_status]);
As far as I can see, the data contains the four elements:
timestamp
order_number
order_created
orders_status
Instead, you can put these elements into any cell on your table. Something like this, for example:
var ss = Spreadsheet.GetActiveSheet();
ss.getRange('A10').setValue(timestamp); // timestamp goes to A10
ss.getRange('B20').setValue(order_number); // order_number goes to B20
ss.getRange('C30').setValue(order_created + order_status); // created + status go to C30
The same way you can add any of these elements to some existing value in some cell, etc. For example:
var old_value = ss.getRange('A2').getValue(); // get value from the cell A2
var new_value = old_value + order_number; // add with order_number
ss.getRange('A2').setValue(new_value); // put the sum back into the cell A2
The main problem is up to you. You have to figure out:
what exactly the elements you're receiving (number, names)
how exactly you want to sort them out (what to add to what... what to put where... etc)
I can't understand it from the example picture.
Here is some reference documentation on Apps Script:
Main Page - Introducing Apps Script.
Sheets Guide - Introduction to Sheets with Apps Script.
Sheets Reference - Where you will find all the details of everything you can do with Sheets in Apps Script.
Remove Duplicate Rows - A good small tutorial that will teach you the basics of Sheets and Ranges and how to manipulate them.
To export all my WooCommerce orders on a scheduled basis, I used a ready-made solution.
I used a WooCommerce API and JSON client. It worked smoothly: I got the WooCommerce API, and the JSON client was implemented in the tool already.
You just need to choose endpoint in the JSON client to get the required data. I exported all orders once a month, so I used the base URL http:// mydomain /wp-json/wc/v3/orders and my endpoint was orders.
You can check this article to understand better how it works for your purpose.
And here is WooCommerce API documentation.
I assume that setting up an export through the Apps Script is more flexible (and based on the answer above, it's working indeed), but I'm not a code guy. So I searched for an easier solution, and the API + JSON client helped.
Hope you'll find it helpful.
I would like to suggest using WooCommerce Google Sheet Plugin

Is there a way to have google form responses to record in sheets depending on what section of the form is filled out?

I made a form with multiple conditional paths and my response sheet is ungodly I could really use some help.
The way I set up the form has a total of 19 sections
Location Dropdown (we have 3)> Machine dropdown (a total of 15)> A Machine Specific measurement section and Submit.
I split the Measurements sections by machine because, I was hoping I could have each section record numbers into separate sheets. This way I could keep each Machine's data on its own google sheet.
So logically I am trying to get MachineX measurements to record sheet X but, Get Machine Y to record In Sheet Y. Is what I'm looking for feasible/ even possible?
I know I can try and organize the form responses into the sheets manually, but I am trying my best to avoid that, cause its gonna take a lot of time out of the week.
Maybe there is a way to organize the form response sheet to filter the data into their appropriate sheets.
I am out of my depth and could really use some help.
You can set up a linked Sheet to the Form and then an Apps Script function that gets the data and prints it into the Sheet.
First you have to create an Installable trigger: On form submit so every time the form is submitted the Sheet will be updated
Once you have your trigger set up, you have to write the function.
I would suggest you to create variables for each sheet you want your data in.
You can select the sheet by name like: sheet.getSheetByName("MachineX")
I recommend setting up the questions in an order that allows you to say:
From question 1 to 6 -> go to "MachineX"
From question 7 to 19 -> go to "MachineY"
Now you have to iterate over the answers and get the latest responses:
- If you just want the latest response to the form you could use something like:
for (var i = formResponses.length - 1; i < formResponses.length; i++)

Is there a Script to create a hyperlink within a column whenever a new row is created in Gsheet?

I am importing information into my Google Sheet which creates a new row automatically. Basically I need a script that when a new row is created, a hyperlink for cell 'V' appears in cell V.
Ive tried using only Google formulas as I have no scripting experience
I have no code sorry, I am a total Noob
Basically I need a script that when a new row is created, a hyperlink for cell 'V' appears in cell V of the new row.
Have you tried using arrayformula? =arrayformula(if(A2:A="",,hyperlink(A2:A,"link label")))
If you put this at the top of the spreadsheet, it will create hyperlinks for all of those URLs.
Maybe a spreadsheet example would help?
https://docs.google.com/spreadsheets/d/1lNfR-G_T7M5d8xi-UK1lLJGGJnxNox6iZYG0eykKV9I/edit#gid=0
If I'm still not understanding, feel free to edit that spreadsheet to make it more accurate for your specific case.

Adding button that adds custom sheet in Google Sheets

I'm working on a Google Sheet to perform analysis on the cyclomatic complexities of the software under test. There's multiple projects, and I've been assigned to, and completed analysis on, one of them. I wish to extend this Spreadsheet, such that, when a user hits "Add Sheet" button, they can create a sheet ready for data insertion and analysis.
The format of the sheet
Thus far, looks like this:
...
Strategy
I know that it's possible (as I have done from experience!) to create a container-bound Google Script to create Sheets. I just don't know how to create a button to do so, let alone at the Spreadsheet level.
Business Requirements
The header row should be copied over and formatted
Custom cells (in the "Already unit-tested?" column) should be insertable, and the "FALSE" one should be inserted on row creation
formulae for average complexity,standard deviation,median complexity,number of files computations should be inserted on spreadsheet creation and update upon row creation/state change of rows
I'm not sure the way to go about all this, let alone the score of this user story.
I’d put the button on a sidebar and in that case it can be any kind of html button you wish.
I'll try insert a menu in my spreadsheet, here you'll find custom menu documentation.
just create a function like newSheet() and trigger it when button is pressed.
for the first row and the format you can use srcRange.copyTo(destRange).
use a drop-down list for the "Already unit-tested?" column using data validation
and for the formulas just type in the formula and use range.setValues().

Referencing cell on other tab in formula

How to reference the same (row,column) on the different tab in the same google spreadsheet document?
So, I want to do something like this:
=SOME_FORMULA('First tab'!(ADDRESS(ROW(),COLUMN()))). This doesn't work.
If the formula isn't apsolutly referenced, entries of Google Forms questionnaire change the reference and mess up the formula. (the formula that looked at row number 5 after insert looks at row number 6) I can't use apsolute referencing ($A$1) because I have to enter it manually.
Can I change the reference on multiple cells? (for one I can use cmd + f4)
I had that annoying reference problem too. If I understand correctly you are trying to get the information on some cells, but every time someone sends information to the spreadsheet by filling up a Form, that reference moves down a row.
The best solution I came up with was to create a new SpreadSheet and import all the information with this:
=importrange("spreadsheet-key","Form Responses!A1:B2107")
That function updates the info in realtime, so you can do all the processing on the new spreadsheet.
Hope this helps.
Do not quite understand what you need. Need to reference a cell in another sheet given coordinates on the current cell where it is located?
If so, the following formula can be useful:
=INDIRECT("First tab!"&ADDRESS(ROW(), COLUMN()))