قالب وردپرس درنا توس
Home / Tips and Tricks / How to Load Your Google Apps Using the Script Editor

How to Load Your Google Apps Using the Script Editor



  Google Apps Script Lede

If you use Google Apps, you may not be able to use it to the full. With Google Apps Script, you can add custom menus and dialogs, create custom functions and macros, and create add-ons to extend Google Docs, Sheets, and Slides.

What is Google Apps Script?

Google Apps Script is a cloud-based development platform for creating custom, lightweight web applications. You can create scalable applications right in your browser that are easy to integrate with Google products.

Apps Script uses the JavaScript language and brings the familiarity of web development and Google products together in one place. This makes it a perfect tool to tailor apps to your business, organization or just to automate worldly tasks.

Google Apps Script lets you create two types of scripts:

  • Standalone: ​​ These scripts are not tied to any service ̵
    1; like Google Docs, Sheets, or Slides. You can perform system-wide functions, much like macros. They are not ideal for distribution to a wider audience because you must copy and paste the code to use it. Examples include browsing your drive for files with specific names or viewing access to your shared files and folders in Drive.
  • Bound: These are linked to a file of Google Docs, Sheets, Forms, or Slides. Bound scripts extend the functionality of a file and perform actions only in that particular file. Examples include adding custom menus, dialog boxes, and sidebars to a service or script that notifies you by e-mail every time you change a specific cell in a worksheet.

If you do not know much JavaScript or have never heard of it before, do not be put off by developing your own script. It's very easy to use Apps Script because it provides a wealth of documentation and examples that you can try for yourself. Here are some simple examples to help you understand how they work.

Creating a stand-alone script

Now that you know what they are, create your first stand-alone script. We'll use a code sample from Google to get the ball rolling, and we'll provide explanations to the lines of code if you're unfamiliar with GoogleScript or JavaScript.

Continue to Google Apps Script. Click on the Hamburger icon in the upper left corner and then on "New Script".

A new untitled project opens with a blank function. However, since we use sample code from Google, you can do this Delete all the text in the file.

 Your Very First Apps Script Feature

Note: To sign up for this script, log in to your Google Account to work.

After deleting the code preinstalled in the file, paste the following code:

  // Initialize your function
Function createADocument () {

// Create a new Google document called "Hello, World!"
var doc = DocumentApp.create (& # 39; Hello, World! & # 39;);

// Access the body of the document and then add a paragraph.
doc.getBody (). appendParagraph (& # 39; This document was created using Google Apps Script. & # 39;);
} 

You must save the script before you can run the code. Click on "File" and then on "Save".

 Click

Rename the project to something to help you remember the script, and then click OK.

 Rename Turn your project into something that tells you what the script is doing, and then click OK

To run your code, click the play icon in the toolbar.

 Click the

icon You must give the script some permissions to access your Google Account through a pop-up window after you click Run for the first time. Click "Check permissions" to see what it needs to access.

 Before the script can run, you must verify the required permissions. Click Check permissions

As this is not a Google approved app, you will receive another warning. In essence, that means unless you know the developer (us) only if you trust him. Click Advanced, and then click Go to CreateNewDoc (or whatever you named this script).

 You receive a Google warning stating that the app you run has not been reviewed by them. Click

Verify the required permissions of the script, and then click Allow.

<img class = "alignnone wp-image-410701 size-full" src = "https://www.howtogeek.com/wp-content/uploads/2019/04/x2019-04-09_11h30_39.png.pagespeed .gp + jp + jw + pj + ws + js + rj + rp + rw + ri + cp + md.ic.5Y8256I3Kg.png "alt =" Check the permissions, and then click Allow [194590385].

Great! Now go to your drive and if everything works, the file "Hello, Welt!" Should be available. Double click on it to open it.

 Navigate to your drive and double-click the newly created file.

When you open the file, the text line from the code appears adding to your document.

 The file contains the text line you added via the script

. If you'd like to receive an email notification when you create the document, you can add a few lines of code to a document to automatically send one to your Google Account. Add the following lines of code after doc.getBody (): appendParagraph (& # 39; This document was created using Google Apps Script. & # 39;); but before the last curly bracket }:

  // Get the URL of the document.
var url = doc.getUrl ();
// get the email address of the active user - that's you.
var email = Session.getActiveUser (). getEmail ();

// Get the name of the document to use as the email subject line.
var subject = doc.getName ();

// Add a new string to the "url" variable to use as e-mail text.
var body = & # 39; link to your document: & # 39; + url;

// Send an e-mail with a link to the document.
GmailApp.sendEmail (email, subject, message); 

Click the "Run" icon.

 Click the

icon Because you have added a few extra lines that require additional permissions, you must go through the same process as before. Click "Check Permissions".

 Before the script can run, you must verify the required permissions. Click Review Privileges

Click Advanced, and then click Go to CreateNewDoc.

Note: Because Google informs you that you are starting unchecked apps, it will receive an email with a security alert that also notifies you. Google does so only in the event that you have not granted access to an unchecked application.

Check the new permissions required by the script, and then click Allow.

 Check the new permission and click Allow

When the document is created, you will receive an email with a link to the file in your Google Drive.

 The email notification sent automatically by the script contains a link to the new document

Clicking on the link takes you directly to the file in your Google Drive.

 The file contains the line of text that is added from the

How to Create script A bound script

For the next example, we'll create a bound Google Sheets script Analyzes existing sheet for duplicate entries in a line and then deletes them.

If you remember earlier, bound scripts work like an add-in to certain files to create one, let's set up an existing Google Sheet worksheet with at least a double data point.

 A double-sheet Google Sheet

Click Tools, then Script Editor.

[19459051ClickonExtrasandonScriptsEditor"width="343"height="201"/>

Google Apps script opens in a new tab with empty script, but this time the script is bound to the sheet from which it will be opened.

 An empty function for your bound script

Delete the empty function as before, and paste the following code:

  // Removes duplicate rows from the current worksheet ,

Function removeDuplicates () {
// Get the current active table
var sheet = SpreadsheetApp.getActiveSheet ();
// Get all values ​​from the rows of the table
var data = sheet.getDataRange (). getValues ​​();
// Create an array for non-duplicates
var newData = [];
// Iterate through the cells of a row
for (var i in data) {
var line = data [i];
var duplicate = false;
for (var j in newData) {
if (row.join () == newData [j] .join ()) {
Duplicate = true;
}
}
// If it is not a duplicate, insert the newData array
if (! duplicate) {
newData.push (line);
}
}
// Delete the old sheet and paste the newData array
sheet.clearContents ();
sheet.getRange (1, 1, newData.length, newData [0] .length) .setValues ​​(newData);
} 

Note: For the script to remove a duplicate, all cells in the row must match.

Save and rename the script, and click the Run icon.

 Click the Run icon

. As you saw in the last script you created, you need to review the permissions that your script requires and give it access to your spreadsheet. Click "Check Permissions" to see what access this script wants.

 Click

Accept the prompts and click Allow to authorize the script.

 Check the permissions, and then click Allow

After completing the execution, go back to your sheet, and as if in magic, all duplicate entries disappear from your file!

 The duplicate data points have

Unfortunately, if your data is in a table (as in the example above), this script does not change the table to the number of entries.


Although these are two pretty simple examples of using Apps Script, the options are almost limitless and it all depends on what you can do with those resources. In the meantime, you can visit the GSuite Devs Github page or Digital Inspiration and look at the stack of sample scripts that you can deploy in your own services to get a better idea of ​​what Apps Script really can do. [19659069]! Function (f, b, e, v, n, t, s) {if (f.fbq) return; n = f.fbq = function () {n.callMethod? n.callMethod.apply (n, arguments): n.queue.push (arguments)}; if (! f._fbq) f._fbq = n; n.push = n; n.loaded =! 0; n.version = & # 39; 2.0 & # 39 ;; n.queue = []; t = b.createElement (e); t.async =! 0; t.src = v; s = b.getElementsByTagName (s) [0]; s.parentNode.insertBefore (t, s)} (window, document, & # 39; script & # 39 ;, & # 39; https: //connect.facebook.net/en_US/fbevents.js&#39;); fbq (& # 39; init & # 39 ;, 335401813750447 & # 39;); fbq (& # 39; track & # 39 ;, & # 39; PageView & # 39;);


Source link