What you will be able to do in this chapter:
- Design a robot that "aggregates sales every morning at 9 and notifies Slack"
- Specific way to write code (blueprint)
- Points to note when using in practice
- Time required: 15 minutes (reading only)
- Stumbling block: Trying to make everything at once and giving up (Start with design!)
"I understand the technology, but what can I use it for after all?" To answer such questions, we will introduce specific usage examples in business (spreadsheet automation, email sending, aggregation) and show design hints.
1. GAS is a "Digital Subordinate who works 24 hours a day without complaining"
If asked "What can you do with GAS?", answer like this. "Everything humans do using Google services (Gmail, Calendar, Spreadsheet, etc.) can be automated."
They (GAS) continue to work while you sleep and on holidays without saying a single complaint. I will introduce "3 iron plate patterns" that are particularly effective.
A. Regular aggregation and report creation (Eliminate morning routine)
- 😫 Before (When humans do it):
- Log in to the management screen at 9 am every morning and download yesterday's sales data in CSV.
- Copy and paste it into a spreadsheet and update the graph.
- Email the boss saying "Updated".
- Time required: 30 minutes every day (10 hours a month)
- Risk: End if you oversleep. Numbers shift due to copy-paste mistakes.
- 😎 After (When digital subordinate does it):
- GAS starts automatically at 9 am every morning.
- Get data and write to spreadsheet.
- Notify chat tool (Slack/Chatwork) "Yesterday's sales were XX yen".
- Time required: 0 minutes (You can be sleeping)
- Merit: Zero mistakes. Zero lateness.
[Practice] How to make this robot? (Blueprint)
Do not write code suddenly, but first make a "blueprint". Beginners give up because they skip this "design".
1. Input (From where?)
- Sales data (This time, let's say "Column A of Spreadsheet" for practice)
2. Processing (What to do?)
- Add all numbers in column A (Calculate total)
3. Output (To where?)
- Notify to Slack's "#sales-report" channel
4. Implementation Image (Code Skeleton) If it is VS Code, it is a professional way to write functions separately like this.
function main() {
// Commander function. Just call subordinates in order.
const salesData = fetchSalesData(); // 1. Get data
const total = calculateTotal(salesData); // 2. Calculate
notifySlack(total); // 3. Notify
}
function fetchSalesData() {
// Process to get data from spreadsheet
}
function calculateTotal(data) {
// Process to calculate total
}
function notifySlack(amount) {
// Process to send to Slack
}
If you do "division of roles" like this, even if you want to "change the notification destination from Slack to Chatwork", you only need to rewrite notifySlack.
This is "easy-to-maintain code".
B. Alert Notification (24-hour Watchman)
- 😫 Before (When humans do it):
- Check inventory management table every hour.
- If you notice "Ah, product A is running low!", call the person in charge of ordering.
- If you overlook it, it will be out of stock and lead to complaints…
- Mental Cost: Cannot focus on other work due to pressure of "Must watch".
- 😎 After (When digital subordinate does it):
- GAS monitors the spreadsheet every 10 minutes.
- The moment the inventory count becomes "5 or less", send a notification to the person in charge's smartphone.
- Effect: Complete liberation from mental stress.
C. Form Linkage (Immediate Response)
- 😫 Before (When humans do it):
- Email comes from inquiry form.
- Manually reply with a thank-you email, transcribe to customer list, and put interview schedule on calendar.
- If response is delayed, customers run away.
- 😎 After (When digital subordinate does it):
- At the same time as form submission, GAS automatically replies "Thank you for your inquiry".
- Transcription to customer list and calendar registration are completed in an instant.
- Effect: Customer satisfaction up.
2. Why do it with "Clasp"?
"You can do that with the browser GAS editor, right?" That's right. However, if you use it for business, Clasp (Local Development) is overwhelmingly advantageous.
Reason 1: Can reuse "Parts"
For example, suppose you wrote "Code to send notification to Slack".
In browser development, when you want to use it in another project, you have to search "Where was that code…" and copy and paste.
With Clasp, if you have a file called slack-notification.js on your computer (workshop), you can reuse it just by copying the file.
You can accumulate "secret sauce" on your PC.
Reason 2: Can revert even if broken (Git)
Accidents like "Ah! It stopped working!" always happen when messing with business systems. It is hard to "undo" in browser development, but if you manage with Git (history management tool) using Clasp, you can "return to yesterday's state" in an instant. This is the strongest insurance for business use.
Reason 3: Not afraid of complex processing
Business logic tends to be complex. Writing 1000 lines of code on a small browser screen is ascetic practice, but with VS Code, you can split files and use powerful search functions, so you can create "easy-to-maintain (hard-to-break) systems".
3. Points to note in operation (Professional perspective)
When actually running the created robot in the company, pay attention to the following points.
- Trigger (Start Switch) Settings
- You can set it like "Every day between 9:00 and 10:00", but you cannot specify in seconds. Caution is required if strict time management is necessary.
- Authority (Who executes)
- GAS runs with "authority of the person who executed". If you retire and your account disappears, the robot also stops.
- It is an iron rule to run important robots with a "robot account (shared account)" rather than an individual account.
- Notification when failed
- Robots also fail sometimes (Spreadsheet cannot be opened, etc.).
- Use a writing style called
try...catchto insure "Email me if it fails".
4. Advice for Beginners: Start Small
Do not try to create a "fully automated system" suddenly. The iron rule of programming is "Make small and grow".
- First, write code to "just output column A of spreadsheet to log".
- Next, modify it to "send the contents of column A to yourself by email".
- Finally, set a trigger to "execute every morning at 9 am".
In this way, accumulating "Done!" is the trick not to give up.
With Clasp and VS Code, the speed of this trial and error becomes many times faster.
Even if you fail, it will not affect the production environment (Google) unless you clasp push. Please experiment without fear.
Frequently Asked Questions (Q&A)
Q. I can't think of anything in my work that can be automated.
A. Look for "Copy-paste" and "Transcription". Excel to Excel, Email to Excel, Web to Excel… The "work of moving data from right to left" that you usually do is all GAS's specialty. First, let's try automating just one "copy-paste work that takes 5 minutes a day".
Q. Can I use GAS freely with a company account?
A. Check the rules of the IT department. In many companies, if Google Workspace is introduced, GAS can also be used, but it may be restricted by security policy. If you are anxious, it is better to practice with a personal Google account first and then propose to the company.
Understanding Check Test
Q1. What are the “3 iron plate patterns” that GAS is good at?
Answer: Regular aggregation/report, Alert notification, Form linkageQ2. What is the biggest merit of using Clasp (local development) in business?
Answer: Code (parts) can be reused, history management with Git is possibleQ3. What is the iron rule when creating an automation system?
Answer: Make small and grow (Don’t aim for full automation suddenly)What to do in the next chapter:
- Correct way to break through "Approval Screen"
- What is "6-minute wall"?
- How to deal with errors (How to read logs)
>> Next Chapter: Chapter 8 Points where beginners always get stuck
Series Index
- [Pinned] Complete Clasp x GAS Guide for Absolute Beginners (ZIDOOKA!)
- Chapter 0: What are GAS and Clasp anyway?
- Chapter 1: Minimum things to know before using Clasp
- Chapter 2: Setting up the environment for Clasp
- Chapter 3: Connecting Google Account and Clasp
- Chapter 4: Creating your first GAS project
- Chapter 5: Writing GAS code
- Chapter 6: Understanding push / pull
- Chapter 7: Image of using GAS for "Real Work" (Current)
- Chapter 8: Points where beginners always get stuck
- Chapter 9: What to do next