Manipulation of Google Form data into one record - google-apps-script

I am designing a service hour record system for a docent service. The user inputs the applier's name, date of activity, number of service hours, and the registration number of all docents participated (separated by commas).
What I want to do is to make one record of all docents and all the activities they have participated. The registration numbers of the entries are split and transposed into one column in another sheet, the details of the activity are copied onto the same sheet, then the details of the docent are taken from a name list and pasted. I would like to ask if there's any way I can automate this process through a function by google apps script?
Included is a sample file with 3 entries, the name list called 'Database' and the intended just in case you don't understand what I wanted.
This is the link to my file

You're going to use the Spreadsheet service provided by AppScript since you put your data into CSV files. To manipulate data from your docent system, you'll need to learn how to import and export from your CSV file too.

Related

Is there a way to fetch url for google sheets from a different spreadsheet using apps script?

I am trying to create a log for all the PDIR reports that are generated in our company. For this purpose, I have written an apps script code that brings forth a format from our master sheet when a product part no. is typed. After filling in the information it allows the user to press the submit button that transfers this PDIR to a PDIR database where all the PDIRs are being stored. Now, what I want to do is, add a feature to the submit button that automatically creates a log for the PDIR report. I have attached the format here for reference. I want to find a way to extract the URL of a particular sheet and add the link in the log next to the invoice, so my employees do not have to waste time finding different invoices and can just search for the invoice no. and have a link ready to take them to it.
Long story short, I want to find a way to get a URL of a sheet from a different spreadsheet using apps script.

Macro to delete the old data

I'm really new to this and would love some help where I'm currently stuck. I've created a macro to clear a spreadsheet. I've tried multiple triggers of onedit and onchange and haven't had luck with my end goal. I'm sending data (about 10 columns and 100 rows into a google sheets via zapier. Basically, I'm refreshing the data by replacing the data. So, before the data comes in, I wanted the macro to delete the old data. However, the macro actually deletes the new data coming in once it posts. Any scripts or workarounds that could help?
From what I know about Zapier it works on timed intervals. You can have a script run on time intervals just before the time Zapier inputs information and delete the old info.
Another approach would probably be to have a intermediary sheet.(Lets call this sheet, "sheet1". The final sheet can be called "sheet2". When Zapier writes data to sheet1 it can trigger the onChanged event. Take the information in sheet2 delete everything, then post the new data to sheet 2.
Finally, Zapier supports webhooks. You can publish your script as a web app and have it do a get or post to the app which runs the delete function. To give it time you can use the delay that Zapier provides.
What you are describing sounds like the perfect candidate for the IMPORTDATA worksheet function. The function is entered in a cell, as are all worksheet functions, and it takes a URL which points to a CSV or TSV file. Once entered the data referred to by the URL is expanded out into the appropriate number of rows and columns. Seeing as the function resides in a single cell you would only need to update that cell when you wanted to change the data. This means that you would no longer need to use a .gs file to remove old data and could instead complete everything from within Zapier. I have answered a question similar to this here, I describe how this is done within Zapier. The only prerequisite is that the data you are using is in either CSV or TSV format.

Scripts: Need to export/copy data from Google Sheet to another (acting as a form submission)

For a quick background, I'm using a single google sheet as a daily "dashboard" for my managers' shift reports. I'm using a few time driven scripts to export each report to pdf and email it to our ops team every night, and another script to clear the data so the report is ready for the next day.
This works well for day-to-day review, but we lack the capability to store daily stats we want to reference months-years down the road. We used Google Forms for this in the past, but I'm determined that we can consolidate both processes.
As imaged, the circled fields on the "dashboard" sheet are the data points I want to export to an archive sheet. Ideally, the data would export to a spreadsheet adding 1 row of MB data followed by CAD data in the next row.
I've played around with a few scripts playing with 'HTML Google Form Submissions', but I couldn't find a solution which could pull in data from another sheet. To make this work, I would need to be able to reference specific cells/ranges as entries to specific form questions.
I've also tried some scripts which copied data to the next empty row of another sheet similar to Google Forms, but it became super buggy and difficult to fine tune.
This sounds like what you are asking for.
function backup(){
var data = SpreadsheetApp.getActiveSheet().getRange("a7:g8").getValues();
var backupss = SpreadsheetApp.openByUrl("backupsheeturl");
var backupsheet = backupss.getSheetByName("backupsheet");
backupsheet.appendRow(data[0]).appendRow(data[1]);
}
Reference:
https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#openById(String)
https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#openByUrl(String)

How to generate an EditResponseUrl() for manually entered rows in a Google Form response spreadheet?

I have an spreadsheet linked with a form and made it as, all the user to edit the response after submit. And connected it with Awesome Table. When i insert a data through the form, the spreadsheet automatically generate the edit response url. this is done by gas. This isworking fine. But, what i want now is, how can i generate the response url for the data which i paste directly to the sheet from another sheet? is it possible? please help me with some suggestions or a piece of code.
Thanks in advance.
It's not possible to do this.
The forms services and the sheets service are two separate services. This is a simplified version of what happens when you submit a response to a form:
The form is submitted.
The forms service stores the response.
The forms service writes the response to a sheet.
When you use the EditResponseURL() method, you're getting the information from step 2), and editing it. This then causes the form to complete step 3) a second time, updating the sheet.
If you write the response directly to the sheet, you're skipping step 1) & 2). If the response is not stored in the form, there's no way to use the EditResponseURL() (As this is a forms only method).
Easy solution: Submit everything via the form, and do not write directly to the sheet.
More complicated solution: Write a custom form that allows you to pull the information in a range of cells from a sheet, update the information, then writes the edited information back to the sheet.
The second Sheet would need to "know" what it was looking for. The second sheet can retrieve anything it needs from the first sheet, but it needs information about what to retrieve. You would need to explicitly record information that matches some kind of key to the information that should be retrieved. The first Sheet could have information on what response is matched to what row of information. You could have an ID that was just sequential numbers, or you could have an ID (key) that encoded the user name, the date, the time, a random number, a row number, etc. if you need/want that. Your essentially designing a database structure.
It might help to define a flow chart of the process.

Uploading Multiple Attachments into Access and allocating automatically

Two days on and I'm ripping my hair out.
I need to upload hundreds of 'png' attachments into a table (i.e. not one by one to each account code) where they automatically find the relevant account code in the table by matching the account code to the attachment file name.
Alternatively I need to upload all the attachments to a single place and then have a search query that allocates these attachments to their specific account codes in a table.
I have been able to come up with a query that allocates ALL of the attachments to ALL of my relevant account codes but cannot allocate specific attachments using the data filename for reference to a specific account code.
I have also been able to create a form that shows the relevant attachment under the data filename but this will not open from this field when I double click it. When I open the attachment itself from the form it just gives the 'manage attachment' box showing every single attachment for me to select the one I want. This is of no use for my customer.
I'm sure it has to be simple but I have spent ages on this so can anyone please help.
Graham