iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🦔

Creating a Contract Management Database in Notion with Slack Notifications for Renewals

に公開
2024/11/12

Introduction

I've started keeping track of contracts in Notion. Here is what I am documenting:

  • Renewal Date
    • Date. Once renewed, I manually update it to the following year.
  • Status
    • e.g., Active, Candidate, Canceled, Free Contract
  • Business Scope
  • FAQ
    • I've included links to FAQs for major contracts (≈SaaS) on the "Check this out for onboarding!" page.
  • Procedures
    • I don't write confidential information, but I do record other procedures.
  • Environment DB
    • For example, I place kintone App databases in the body. I documented the Apps to explain how to use each one.

I chose Notion because it supports Markdown and makes it easy to attach images, but the notification system was a bottleneck, so I wrote a program using GAS.

code

main.gs
function alertSaaSUpdate(){
  const alertList = getSaaSList().reduce((alertList, saas) => {
    const alertText = saas.getAlertText();
    if(alertText) alertList.push(alertText);
    return alertList;
  }, []);
  
  if(!alertList.length) return;
  slackChannel(
    <slack token>,
    '契約更新確認\n\n' + alertList.join('\n')
  );
}
SaaS.gs
class SaaS{
  constructor(json){
    this.name = json.properties.契約名.title.map(t => t.plain_text).join('');
    this.status = json.properties.ステータス.status.name;
    this.tagList = json.properties.タグ.multi_select;
    this.updateDate = dayjs.dayjs(
      json.properties['契約更新日'].date?.start ? json.properties['契約更新日'].date?.start : '-'
    );
  }

  getAlertText(){
    if(this.status === '契約中' && dayjs.dayjs().add(4, 'months').isAfter(this.updateDate)){
      return `契約確認 ${this.name}, 更新日${this.updateDate.format('YYYY/MM/DD')}`;
    }
  }

  getUpdateDate(){
    return this.updateDate;
  }
}
notion.gs
const NOTION = {
  token: <token>,
  db: {
    saas: <id>,
  },
};



function getSaaSList(){
  return Notion.initManager(NOTION.token).query(NOTION.db.saas).map(json => new SaaS(json));
}

Note that "Notion" refers to the following library:
https://zenn.dev/nag8/articles/4fa5aa95f69577

Result

As I thought, programming allows for more flexible notification settings.

Discussion