https://github.com/tanaikech/syncgooglescriptrun
This is a Javascript library to use "google.script.run" with the synchronous process.
https://github.com/tanaikech/syncgooglescriptrun
dialog google-apps-script javascript-library js-library sidebar synchronous web-apps
Last synced: 8 months ago
JSON representation
This is a Javascript library to use "google.script.run" with the synchronous process.
- Host: GitHub
- URL: https://github.com/tanaikech/syncgooglescriptrun
- Owner: tanaikech
- License: mit
- Created: 2019-09-13T05:49:04.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-03-22T06:07:14.000Z (about 5 years ago)
- Last Synced: 2025-09-03T02:03:19.849Z (10 months ago)
- Topics: dialog, google-apps-script, javascript-library, js-library, sidebar, synchronous, web-apps
- Language: JavaScript
- Size: 4.88 KB
- Stars: 15
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# syncGoogleScriptRun
[](https://travis-ci.org/tanaikech/syncGoogleScriptRun)
[](LICENCE)
# Overview
This is a Javascript library to use "google.script.run" with the synchronous process.
# Description
When I create Web Apps, add-on using a side bar and dialog, there is the case that I want to use `google.script.run` with the synchronous process. As you know, [`google.script.run` works with the asynchronous process](https://developers.google.com/apps-script/guides/html/reference/run). So in order to use it as the synchronous process, the script is required to be prepared. I also saw several issues for such situation at Stackoverflow and other sites. I thought that when the script for achieving this was prepared as a library, it might be useful for users. So I created this.
# Install
```html
```
Or, using jsdelivr cdn
```html
```
- Of course, you can use this by directly copying and paste the script of [syncGoogleScriptRun.js](https://github.com/tanaikech/syncGoogleScriptRun/blob/master/syncGoogleScriptRun.js) to the script editor.
# Method
| Method | Explanation |
| :-------------------------- | :----------------------------------------------------------------- |
| syncGoogleScriptRun(object) | Run a function of Google Apps Script with the synchronous process. |
- `object`: There are 2 properties.
- `gasFunction`: Function name of Google Apps Script side.
- `arguments`: Arguments for the function.
# Usage
## Sample script
In this sample script, the result is returned every 1 second.
When you use the following sample script, please copy and paste the following scripts to the container-bound script of Spreadsheet. And run `openDialog()`. By this, a dialog is opened at Spreadsheet. When you clicked the button, you can see the result at the console.
#### HTML side: `index.html`
```HTML
async function run() {
for (let i = 0; i < 5; i++) {
const resource = {
gasFunction: "myFunction", // Function name of Google Apps Script side
arguments: i // Arguments for the function
};
const res = await syncGoogleScriptRun(resource).catch(e => {throw new Error(e)});
console.log(res);
}
}
```
#### Google Apps Script side: `Code.gs`
```javascript
function myFunction(e) {
Utilities.sleep(1000);
return e;
}
function openDialog() {
var html = HtmlService.createHtmlOutputFromFile("index");
SpreadsheetApp.getUi().showModalDialog(html, "sample");
}
```
#### Result
When the button of "Run script" is clicked, you can see the following result at the console.
```
0
1
2
3
4
```
---
# Licence
[MIT](LICENCE)
# Author
[Tanaike](https://tanaikech.github.io/about/)
If you have any questions and commissions for me, feel free to tell me.
# Update History
- v1.0.0 (September 13, 2019)
1. Initial release.
[TOP](#top)