質問編集履歴
2
idを公開してしまったので変更させていただきました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -74,7 +74,7 @@
|
|
74
74
|
function doPost(e) {
|
75
75
|
// 各種データの取得
|
76
76
|
const json_data = JSON.parse(e.postData.getDataAsString());
|
77
|
-
const sheet_id = "
|
77
|
+
const sheet_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
78
78
|
|
79
79
|
// 管理表で商品の売上数を計上
|
80
80
|
const sheet_name1 = "管理表";
|
1
質問が至らず、コードが冗長だったため主要部分に収めました。情報を欠落させてしまっているかもと懸念し、最後に元のコードを記載しておきます。
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,6 +20,52 @@
|
|
20
20
|
### 該当のソースコード
|
21
21
|
|
22
22
|
```gas
|
23
|
+
doPost(e){
|
24
|
+
const json_data = JSON.parse(e.postData.getDataAsString());
|
25
|
+
const result = HtmlService.createHtmlOutpustFromFile("result");
|
26
|
+
result.data = "付随したいデータ";
|
27
|
+
|
28
|
+
return result.evaluate();
|
29
|
+
}
|
30
|
+
|
31
|
+
function get_url(){
|
32
|
+
// gasのURL取得関数(jsで呼び出す)
|
33
|
+
return ScriptApp.getService().getUrl();
|
34
|
+
}
|
35
|
+
```
|
36
|
+
```js(index.html)
|
37
|
+
function send_data() {
|
38
|
+
google.script.run.withSuccessHandler(e => {
|
39
|
+
const URL = e;
|
40
|
+
const postparam = {
|
41
|
+
"method" : "POST",
|
42
|
+
"mode" : "no-cors",
|
43
|
+
"Content-Type" : "application/x-www-form-urlencoded",
|
44
|
+
"body" : JSON.stringify(item_dict)
|
45
|
+
};
|
46
|
+
|
47
|
+
const res = fetch(URL, postparam).then(response => response).then(data => {
|
48
|
+
// 読み取るタイミングやfetchの使い方が曖昧なため、これで合っているかすら疑問
|
49
|
+
// オブジェクトは取得できているが処理の方法を理解できていない、、?
|
50
|
+
console.log(data);
|
51
|
+
});
|
52
|
+
}).get_url();
|
53
|
+
}
|
54
|
+
```
|
55
|
+
|
56
|
+
### 試したこと
|
57
|
+
|
58
|
+
doGetでresult.htmlを返却する事は考えたのですが、購入商品情報等のjsonを渡す方法をどう繋げればいよのか、また余計な考えかもしれませんがスマートに処理ができるのでは、、と考えdoPostでの画面遷移の方法を模索しています。
|
59
|
+
|
60
|
+
質問の中で、至らない所などあるとは思いますが
|
61
|
+
どうぞご教授のほどよろしくお願いいたします。
|
62
|
+
|
63
|
+
### 補足情報(FW/ツールのバージョンなど)
|
64
|
+
|
65
|
+
html, gas, google chromeなどは最新だと思います
|
66
|
+
|
67
|
+
```元コード
|
68
|
+
// 以下gas -----------------------------------------------------------------------
|
23
69
|
function doGet(e) {
|
24
70
|
// 最初に商品読み取り用のページを表示させる。(ここは表示できる)
|
25
71
|
return HtmlService.createHtmlOutputFromFile("index");
|
@@ -28,7 +74,7 @@
|
|
28
74
|
function doPost(e) {
|
29
75
|
// 各種データの取得
|
30
76
|
const json_data = JSON.parse(e.postData.getDataAsString());
|
31
|
-
const sheet_id = "
|
77
|
+
const sheet_id = "19moEZH2Y9B5E6bT18iayY-gasGo4-bQOhnXrYZ0sK6s";
|
32
78
|
|
33
79
|
// 管理表で商品の売上数を計上
|
34
80
|
const sheet_name1 = "管理表";
|
@@ -83,16 +129,14 @@
|
|
83
129
|
result.without = amount - tax;
|
84
130
|
|
85
131
|
// 返却するが、表示できない
|
86
|
-
return result.
|
132
|
+
return result.evaluate;
|
87
133
|
}
|
88
134
|
|
89
135
|
function get_url(){
|
90
136
|
// js側でrun関数で呼び出すデプロイurl取得用の関数
|
91
137
|
return ScriptApp.getService().getUrl();
|
92
138
|
}
|
93
|
-
}
|
94
|
-
```
|
95
|
-
|
139
|
+
// 以下index.html -----------------------------------------------------------------------
|
96
140
|
<!DOCTYPE html>
|
97
141
|
<html>
|
98
142
|
<head>
|
@@ -235,53 +279,3 @@
|
|
235
279
|
</script>
|
236
280
|
</body>
|
237
281
|
</html>
|
238
|
-
```
|
239
|
-
```result.html
|
240
|
-
<!DOCTYPE html>
|
241
|
-
<!-- 返却用html -->
|
242
|
-
<html>
|
243
|
-
<head>
|
244
|
-
<base target="_top">
|
245
|
-
</head>
|
246
|
-
<body>
|
247
|
-
<div>
|
248
|
-
<h1 class="top center">領収証</h1>
|
249
|
-
<p class="no right"></p>
|
250
|
-
<p class="date right"><?=date ?></p>
|
251
|
-
<p class="dear left"></p>
|
252
|
-
<h1 class="amount center"><?=amount ?></h1>
|
253
|
-
<p class="proviso center">但し</p>
|
254
|
-
<p class="jouki center">上記正に領収しました。</p>
|
255
|
-
<div class="wrapper left">
|
256
|
-
<p class="items center">内訳</p>
|
257
|
-
<div class="without center">
|
258
|
-
<p class="without title left">税別金額</p>
|
259
|
-
<p class="without num center"><?=without ?></p>
|
260
|
-
</div>
|
261
|
-
<div class="tax center">
|
262
|
-
<p class="tax title left">消費税額</p>
|
263
|
-
<p class="tax num center"><?=tax ?></p>
|
264
|
-
</div>
|
265
|
-
</div>
|
266
|
-
<div class="wrapper right">
|
267
|
-
<p class="zip"><?=zip ?></p>
|
268
|
-
<p class="address"><?=address ?></p>
|
269
|
-
<p class="corp"><?=corp ?></p>
|
270
|
-
<p class="phone"><?=phone ?></p>
|
271
|
-
</div>
|
272
|
-
</div>
|
273
|
-
</body>
|
274
|
-
</html>
|
275
|
-
```
|
276
|
-
|
277
|
-
### 試したこと
|
278
|
-
|
279
|
-
doGetでresult.htmlを返却する事は考えたのですが、購入商品情報等のjsonを渡す方法をどう繋げればいよのか、また余計な考えかもしれませんがスマートに処理ができるのでは、、と考えdoPostでの画面遷移の方法を模索しています。
|
280
|
-
|
281
|
-
質問の中で、至らない所などあるとは思いますが
|
282
|
-
どうぞご教授のほどよろしくお願いいたします。
|
283
|
-
|
284
|
-
### 補足情報(FW/ツールのバージョンなど)
|
285
|
-
|
286
|
-
html, gas, google chromeなどは最新だと思います
|
287
|
-
|