Help us understand the problem. What is going on with this article?

Google Apps Scriptで、同一プロジェクト内で分割された.gsファイルの関数を使う方法

More than 1 year has passed since last update.

タイトルのように同じプロジェクトで、.gsファイルを分割してコードの見通しを良くしたいということがあると思います。
例えば slack.gs はSlackに通知する処理を書いて、main.gs にはmain処理がありそのmainの中で slack.gs にある関数を使うなど。

そんな時は 何も考えずに他の.gsファイルに記述された関数を書けばOK です。

以下は一例です。

  • slack.gs
function notifySlack(payload) {
  var payload = {
    text: message,
    icon_emoji: ":smile:",
    username: "Google Apps Script",
  }
  var options = {
    method: "post",
    contentType: "applidation/json;",
    payload: JSON.stringify(payload),
  }

  UrlFetchApp.fetch("<INCOMMING WEBHOOK URL>", options);
}
  • main.gs
function main() {
  // 何らかの処理...

  // Slackへ通知
  notifySlack('SOME MESSAGE!')
}

require等必要なく、これだけでOKです。
便利ですね、Google Apps Script。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした