Automating Processes In Five: Using Jobs
Tags: jobs, automatingprocesses, functions, taskmanagement
Published: 2023-11-07 21:15:00

<!-- wp:paragraph -->
<p>Welcome to Five Labs, a step-by-step guide to building applications using Five. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This lab will guide you through the process of creating Jobs in Five. Jobs in Five are utilized to <strong>automate functions</strong>, allowing you to <strong>schedule and execute them on a recurring basis</strong>. The objective of the tutorial is to:</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><!-- wp:list-item -->
<li>Download and import the <a href="https://five.co/use-cases/task-management-system/" data-type="URL" data-id="https://five.co/use-cases/task-management-system/">Task Management Template</a> in Five.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Write and manage JavaScript functions.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Adding a reminder feature in the Task Management Template.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Creating Jobs in Five.</li>
<!-- /wp:list-item --></ol>
<!-- /wp:list -->

<!-- wp:separator -->
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<!-- /wp:separator -->

<!-- wp:heading -->
<h2 class="wp-block-heading">Lab Objectives</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>By the end of this lab, you will have learned how to write Jobs in Five that can run your Actions in Five on a recurring basis. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Typical use cases for jobs are, for example, scheduling an email report on a weekly basis, checking for new orders daily, or notifying users of incoming requests every minute. Five's Jobs feature lets us schedule functions at regular, time-based intervals.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To get started, here’s what we need:</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><!-- wp:list-item -->
<li>Have Five installed in your system or run Five on the cloud (with a paid subscription).</li>
<!-- /wp:list-item --></ol>
<!-- /wp:list -->

<!-- wp:separator -->
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<!-- /wp:separator -->

<!-- wp:paragraph {"align":"center"} -->
<p class="has-text-align-center"><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color"><span style="color: #f1ebda; background-color: #4588d8; font-size: calc(12px + 0.390625vw);"><strong>Don't Feel Like Reading?</strong></span></mark>&nbsp;</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"align":"center"} -->
<p class="has-text-align-center">Watch the YouTube video and learn how to use jobs to schedule tasks in Five.</p>
<!-- /wp:paragraph -->

<!-- wp:embed {"url":"https://www.youtube.com/watch?v=E25v9v7iyFM\u0026t=2s","type":"video","providerNameSlug":"youtube","responsive":true,"className":"wp-embed-aspect-16-9 wp-has-aspect-ratio"} -->
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
https://www.youtube.com/watch?v=E25v9v7iyFM&amp;t=2s
</div></figure>
<!-- /wp:embed -->

<!-- wp:separator -->
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<!-- /wp:separator -->

<!-- wp:heading -->
<h2 class="wp-block-heading">Step 1: Downloading And Importing The Task Management Template</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>First, let's import a template into Five so we can get a headstart and after that, we can jump right into our functions.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For this tutorial, we will be using the <a href="https://five.co/use-cases/task-management-system/" data-type="URL" data-id="https://five.co/use-cases/task-management-system/">Task Management Template</a>, and we will be adding a Reminder feature to this app such that we get a notification whenever a task is due.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Download the template from the link above and import it into Five.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1726,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://five.co/wp-content/uploads/2023/09/Frame-26-1024x548.png" alt="" class="wp-image-1726"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Click the '<strong>Manage</strong>' button to enter the development environment, then select '<strong>Database Modeler</strong>' from the '<strong>Data</strong>' menu to view the app's database.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The Task Management application is straightforward and consists of four database tables: tasks, reminders, task categories and categories.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It also features some pre-constructed forms, charts, and queries for your perusal. We will use the 'Reminder' table to build a simple reminder feature for this app.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1727,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://five.co/wp-content/uploads/2023/09/Frame-27-1024x548.png" alt="" class="wp-image-1727"/></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2 class="wp-block-heading">Step 2: Defining JavaScript Functions</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Now that we have an understanding of our application, let's jump into writing some code. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Inside Five, navigate to the ‘<strong>Code Editor</strong>’, which you can find inside '<strong>Logic</strong>'.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Click on the ‘<strong>+</strong>’ icon to initiate a new function. Assign it a meaningful name (we will call it sendReminder) and choose your preferred language, either TypeScript or JavaScript.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1728,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://five.co/wp-content/uploads/2023/09/image-2.png" alt="" class="wp-image-1728"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>We will start by retrieving all the reminder dates from our table. We can do this by invoking a simple SQL statement through our function. </p>
<!-- /wp:paragraph -->

<!-- wp:kevinbatdorf/code-block-pro {"code":"function sendReminder(five, context, result) {\n  let sqlStatement = 'Select ReminderDate From Reminders'\n  let queryResults = five.executeQuery(sqlStatement, 0);\n  if (!queryResults.isOk()) {\n          five.createError(queryResults);\n  }\n   return five.success(result);\n}","codeHTML":"\u003cpre class=\u0022shiki one-dark-pro\u0022 style=\u0022background-color: #282c34\u0022 tabindex=\u00220\u0022\u003e\u003ccode\u003e\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003efunction\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003esendReminder\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75; font-style: italic\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #E06C75; font-style: italic\u0022\u003econtext\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #E06C75; font-style: italic\u0022\u003eresult\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e) {\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e  \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003elet\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003esqlStatement\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026#39;Select ReminderDate From Reminders\u0026#39;\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e  \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003elet\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003equeryResults\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eexecuteQuery\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003esqlStatement\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #D19A66\u0022\u003e0\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e  \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003eif\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e (\u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e!\u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003equeryResults\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eisOk\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e()) {\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e          \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003ecreateError\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003equeryResults\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e  }\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e   \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003ereturn\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003esuccess\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003eresult\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e}\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e","language":"javascript","theme":"one-dark-pro","bgColor":"#282c34","textColor":"#abb2bf","fontSize":".875rem","fontFamily":"Code-Pro-JetBrains-Mono","lineHeight":"1.25rem","headerType":"headlights","seeMoreString":"","seeMoreAfterLine":"","seeMoreTransition":false,"lineHighlightColor":"rgba(134, 167, 228, 0.2)","copyButton":true,"buttonTheme":"heroicons"} -->
<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="function sendReminder(five, context, result) {
  let sqlStatement = 'Select ReminderDate From Reminders'
  let queryResults = five.executeQuery(sqlStatement, 0);
  if (!queryResults.isOk()) {
          five.createError(queryResults);
  }
   return five.success(result);
}" style="color:#abb2bf;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki one-dark-pro" style="background-color: #282c34" tabindex="0"><code><span class="line"><span style="color: #C678DD">function</span><span style="color: #ABB2BF"> </span><span style="color: #61AFEF">sendReminder</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75; font-style: italic">five</span><span style="color: #ABB2BF">, </span><span style="color: #E06C75; font-style: italic">context</span><span style="color: #ABB2BF">, </span><span style="color: #E06C75; font-style: italic">result</span><span style="color: #ABB2BF">) {</span></span>
<span class="line"><span style="color: #ABB2BF">  </span><span style="color: #C678DD">let</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">sqlStatement</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #98C379">&#39;Select ReminderDate From Reminders&#39;</span></span>
<span class="line"><span style="color: #ABB2BF">  </span><span style="color: #C678DD">let</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">queryResults</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">executeQuery</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">sqlStatement</span><span style="color: #ABB2BF">, </span><span style="color: #D19A66">0</span><span style="color: #ABB2BF">);</span></span>
<span class="line"><span style="color: #ABB2BF">  </span><span style="color: #C678DD">if</span><span style="color: #ABB2BF"> (</span><span style="color: #56B6C2">!</span><span style="color: #E5C07B">queryResults</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">isOk</span><span style="color: #ABB2BF">()) {</span></span>
<span class="line"><span style="color: #ABB2BF">          </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">createError</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">queryResults</span><span style="color: #ABB2BF">);</span></span>
<span class="line"><span style="color: #ABB2BF">  }</span></span>
<span class="line"><span style="color: #ABB2BF">   </span><span style="color: #C678DD">return</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">success</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">result</span><span style="color: #ABB2BF">);</span></span>
<span class="line"><span style="color: #ABB2BF">}</span></span></code></pre></div>
<!-- /wp:kevinbatdorf/code-block-pro -->

<!-- wp:paragraph -->
<p>We use <code>five.executeQuery()</code> and then we use<code>.isOk()</code> to check if the response resulted in any error. Since the response is a JSON object we can easily map through our results.</p>
<!-- /wp:paragraph -->

<!-- wp:kevinbatdorf/code-block-pro {"code":"function sendReminder(five, context, result) {\n  let sqlStatement = 'Select ReminderDate From Reminders'\n  let queryResults = five.executeQuery(sqlStatement, 0);\n  \n  if (!queryResults.isOk()) {\n          five.createError(queryResults);\n  }\n  \n  queryResults.values.map(item =\u003e {\n        five.log(\u0022Hello World\u0022)\n        let currentDate = Date.now();\n        let reminderDate = new Date(item.ReminderDate)\n        if(currentDate \u003e= reminderDate){\n            five.showMessage(\u0022You have a task due\u0022)\n        }\n  })\n   return five.success(result);\n}","codeHTML":"\u003cpre class=\u0022shiki one-dark-pro\u0022 style=\u0022background-color: #282c34\u0022 tabindex=\u00220\u0022\u003e\u003ccode\u003e\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003efunction\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003esendReminder\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75; font-style: italic\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #E06C75; font-style: italic\u0022\u003econtext\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #E06C75; font-style: italic\u0022\u003eresult\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e) {\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e  \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003elet\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003esqlStatement\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026#39;Select ReminderDate From Reminders\u0026#39;\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e  \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003elet\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003equeryResults\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eexecuteQuery\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003esqlStatement\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #D19A66\u0022\u003e0\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e  \u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e  \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003eif\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e (\u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e!\u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003equeryResults\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eisOk\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e()) {\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e          \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003ecreateError\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003equeryResults\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e  }\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e  \u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e  \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003equeryResults\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003evalues\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003emap\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75; font-style: italic\u0022\u003eitem\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003e=\u0026gt;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e {\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003elog\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026quot;Hello World\u0026quot;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e)\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003elet\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003ecurrentDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003eDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003enow\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e();\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003elet\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003ereminderDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003enew\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003eitem\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003eReminderDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e)\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003eif\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003ecurrentDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e\u0026gt;=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003ereminderDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e){\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e            \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eshowMessage\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026quot;You have a task due\u0026quot;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e)\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        }\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e  })\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e   \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003ereturn\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003esuccess\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003eresult\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e}\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e","language":"javascript","theme":"one-dark-pro","bgColor":"#282c34","textColor":"#abb2bf","fontSize":".875rem","fontFamily":"Code-Pro-JetBrains-Mono","lineHeight":"1.25rem","headerType":"headlights","seeMoreString":"","seeMoreAfterLine":"","seeMoreTransition":false,"lineHighlightColor":"rgba(134, 167, 228, 0.2)","copyButton":true,"buttonTheme":"heroicons"} -->
<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="function sendReminder(five, context, result) {
  let sqlStatement = 'Select ReminderDate From Reminders'
  let queryResults = five.executeQuery(sqlStatement, 0);
  
  if (!queryResults.isOk()) {
          five.createError(queryResults);
  }
  
  queryResults.values.map(item =&gt; {
        five.log(&quot;Hello World&quot;)
        let currentDate = Date.now();
        let reminderDate = new Date(item.ReminderDate)
        if(currentDate &gt;= reminderDate){
            five.showMessage(&quot;You have a task due&quot;)
        }
  })
   return five.success(result);
}" style="color:#abb2bf;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki one-dark-pro" style="background-color: #282c34" tabindex="0"><code><span class="line"><span style="color: #C678DD">function</span><span style="color: #ABB2BF"> </span><span style="color: #61AFEF">sendReminder</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75; font-style: italic">five</span><span style="color: #ABB2BF">, </span><span style="color: #E06C75; font-style: italic">context</span><span style="color: #ABB2BF">, </span><span style="color: #E06C75; font-style: italic">result</span><span style="color: #ABB2BF">) {</span></span>
<span class="line"><span style="color: #ABB2BF">  </span><span style="color: #C678DD">let</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">sqlStatement</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #98C379">&#39;Select ReminderDate From Reminders&#39;</span></span>
<span class="line"><span style="color: #ABB2BF">  </span><span style="color: #C678DD">let</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">queryResults</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">executeQuery</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">sqlStatement</span><span style="color: #ABB2BF">, </span><span style="color: #D19A66">0</span><span style="color: #ABB2BF">);</span></span>
<span class="line"><span style="color: #ABB2BF">  </span></span>
<span class="line"><span style="color: #ABB2BF">  </span><span style="color: #C678DD">if</span><span style="color: #ABB2BF"> (</span><span style="color: #56B6C2">!</span><span style="color: #E5C07B">queryResults</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">isOk</span><span style="color: #ABB2BF">()) {</span></span>
<span class="line"><span style="color: #ABB2BF">          </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">createError</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">queryResults</span><span style="color: #ABB2BF">);</span></span>
<span class="line"><span style="color: #ABB2BF">  }</span></span>
<span class="line"><span style="color: #ABB2BF">  </span></span>
<span class="line"><span style="color: #ABB2BF">  </span><span style="color: #E5C07B">queryResults</span><span style="color: #ABB2BF">.</span><span style="color: #E5C07B">values</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">map</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75; font-style: italic">item</span><span style="color: #ABB2BF"> </span><span style="color: #C678DD">=&gt;</span><span style="color: #ABB2BF"> {</span></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">log</span><span style="color: #ABB2BF">(</span><span style="color: #98C379">&quot;Hello World&quot;</span><span style="color: #ABB2BF">)</span></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #C678DD">let</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">currentDate</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">Date</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">now</span><span style="color: #ABB2BF">();</span></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #C678DD">let</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">reminderDate</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #C678DD">new</span><span style="color: #ABB2BF"> </span><span style="color: #61AFEF">Date</span><span style="color: #ABB2BF">(</span><span style="color: #E5C07B">item</span><span style="color: #ABB2BF">.</span><span style="color: #E06C75">ReminderDate</span><span style="color: #ABB2BF">)</span></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #C678DD">if</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">currentDate</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">&gt;=</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">reminderDate</span><span style="color: #ABB2BF">){</span></span>
<span class="line"><span style="color: #ABB2BF">            </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">showMessage</span><span style="color: #ABB2BF">(</span><span style="color: #98C379">&quot;You have a task due&quot;</span><span style="color: #ABB2BF">)</span></span>
<span class="line"><span style="color: #ABB2BF">        }</span></span>
<span class="line"><span style="color: #ABB2BF">  })</span></span>
<span class="line"><span style="color: #ABB2BF">   </span><span style="color: #C678DD">return</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">success</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">result</span><span style="color: #ABB2BF">);</span></span>
<span class="line"><span style="color: #ABB2BF">}</span></span></code></pre></div>
<!-- /wp:kevinbatdorf/code-block-pro -->

<!-- wp:paragraph -->
<p>We simply iterate through each date and compare the set reminder date to the current date; if it's due, we display a message using <code>five.showMessage()</code>. We have also used <code>five.log()</code> to test if the function is working or not when we call it.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Now that our function is somewhat prepared, let’s test it first. We will start by attaching our function to a Test process. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Begin by navigating to Processes: click on ‘<strong>Tasks</strong>’, and then on ‘<strong>Processes</strong>’</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1729,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://five.co/wp-content/uploads/2023/09/image-3.png" alt="" class="wp-image-1729"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Create a new process by clicking on the yellow ‘<strong>+</strong>’ button and giving it a name (we will call it ReminderProcess). </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>After that click on the ‘<strong>Events</strong>’ tab and since&nbsp;<a href="https://help.five.org/2.1/docs/api/Events/introduction-to-fives-events" target="_blank" rel="noreferrer noopener">Five supports event-driven programming</a>&nbsp;it will show you a list of events that the process goes through. We will attach our function to the ‘<strong>Do Complete</strong>’ event. Check out the screenshot below to see what this should look like inside Five. Save everything by clicking the tick mark. </p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1730,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://five.co/wp-content/uploads/2023/09/Frame-28-1-1024x548.png" alt="" class="wp-image-1730"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Next, let’s put our process into a menu so that we can access it in our end-user application. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Navigate to ‘<strong>Visual</strong>‘ and then click on ‘<strong>Menu</strong>‘, we will create a new menu item, and then in the ‘<strong>Action</strong>‘ field we will select our process.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1731,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://five.co/wp-content/uploads/2023/09/Frame-29-1024x548.png" alt="" class="wp-image-1731"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Let’s run our application now. We will test our function in debug mode. This can be done by simply clicking on the ▶️ with the magnifying glass on the header.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1732,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://five.co/wp-content/uploads/2023/09/image-4.png" alt="" class="wp-image-1732"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Five will now run your application. But now you’ll also have access to the inspector, which you will be able to find minimized on the right. Maximize it by clicking on the 🔎 icon which will cause it to expand.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Now, select our <code>ReminderProcess</code> from the menus on the left, then click the check button in the top right to execute our process, which will trigger the ‘<strong>Do Run</strong>’ event.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1733,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://five.co/wp-content/uploads/2023/09/Frame-30-1024x548.png" alt="" class="wp-image-1733"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>When we run our process, we receive a message box, and the inspector also displays our logs, indicating our function is operating as intended.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Now let's go back to our function and add the final changes. In order for jobs to work in Five our code should have a connection with our database.</p>
<!-- /wp:paragraph -->

<!-- wp:kevinbatdorf/code-block-pro {"code":"function sendReminder(five, context, result) {\n    const db = five.getDatabaseConnectionByID('TaskMageDB')\n\n    if (!db.isOk()) {\n\n        return five.createError(db, 'Connect to database failed');  \n\n    }\n\n    const tx = five.startTransaction(db);\n\n    if (!tx.isOk()) {\n\n        return five.createError(tx, 'Create transaction failed');  \n\n    }\n\n    let sqlStatement = 'Select ReminderDate From Reminders'\n    let queryResults = five.executeQuery(sqlStatement, 0);\n    \n    if (!queryResults.isOk()) {\n        five.createError(queryResults);\n    }\n\n    queryResults.values.map(item =\u003e {\n        five.log(\u0022It works\u0022);\n        let currentDate = Date.now();\n        let reminderDate = new Date(item.ReminderDate)\n        if(currentDate \u003e= reminderDate){\n            five.showMessage(\u0022You have a task due\u0022)\n        }\n    })\n    five.commit(tx)\n    return five.success(result);\n}","codeHTML":"\u003cpre class=\u0022shiki one-dark-pro\u0022 style=\u0022background-color: #282c34\u0022 tabindex=\u00220\u0022\u003e\u003ccode\u003e\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003efunction\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003esendReminder\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75; font-style: italic\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #E06C75; font-style: italic\u0022\u003econtext\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #E06C75; font-style: italic\u0022\u003eresult\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e) {\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003econst\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003edb\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003egetDatabaseConnectionByID\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026#39;TaskMageDB\u0026#39;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e)\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003eif\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e (\u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e!\u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003edb\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eisOk\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e()) {\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003ereturn\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003ecreateError\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003edb\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026#39;Connect to database failed\u0026#39;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);  \u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    }\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003econst\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003etx\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003estartTransaction\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003edb\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003eif\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e (\u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e!\u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003etx\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eisOk\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e()) {\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003ereturn\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003ecreateError\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003etx\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026#39;Create transaction failed\u0026#39;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);  \u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    }\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003elet\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003esqlStatement\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026#39;Select ReminderDate From Reminders\u0026#39;\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003elet\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003equeryResults\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eexecuteQuery\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003esqlStatement\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #D19A66\u0022\u003e0\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003eif\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e (\u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e!\u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003equeryResults\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eisOk\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e()) {\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003ecreateError\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003equeryResults\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    }\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003equeryResults\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003evalues\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003emap\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75; font-style: italic\u0022\u003eitem\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003e=\u0026gt;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e {\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003elog\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026quot;It works\u0026quot;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003elet\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003ecurrentDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003eDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003enow\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e();\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003elet\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003ereminderDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003enew\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003eitem\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003eReminderDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e)\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003eif\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003ecurrentDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e\u0026gt;=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003ereminderDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e){\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e            \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eshowMessage\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026quot;You have a task due\u0026quot;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e)\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        }\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    })\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003ecommit\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003etx\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e)\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003ereturn\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003esuccess\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003eresult\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e}\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e","language":"javascript","theme":"one-dark-pro","bgColor":"#282c34","textColor":"#abb2bf","fontSize":".875rem","fontFamily":"Code-Pro-JetBrains-Mono","lineHeight":"1.25rem","headerType":"headlights","seeMoreString":"","seeMoreAfterLine":"","seeMoreTransition":false,"lineHighlightColor":"rgba(134, 167, 228, 0.2)","copyButton":true,"buttonTheme":"heroicons"} -->
<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="function sendReminder(five, context, result) {
    const db = five.getDatabaseConnectionByID('TaskMageDB')

    if (!db.isOk()) {

        return five.createError(db, 'Connect to database failed');  

    }

    const tx = five.startTransaction(db);

    if (!tx.isOk()) {

        return five.createError(tx, 'Create transaction failed');  

    }

    let sqlStatement = 'Select ReminderDate From Reminders'
    let queryResults = five.executeQuery(sqlStatement, 0);
    
    if (!queryResults.isOk()) {
        five.createError(queryResults);
    }

    queryResults.values.map(item =&gt; {
        five.log(&quot;It works&quot;);
        let currentDate = Date.now();
        let reminderDate = new Date(item.ReminderDate)
        if(currentDate &gt;= reminderDate){
            five.showMessage(&quot;You have a task due&quot;)
        }
    })
    five.commit(tx)
    return five.success(result);
}" style="color:#abb2bf;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki one-dark-pro" style="background-color: #282c34" tabindex="0"><code><span class="line"><span style="color: #C678DD">function</span><span style="color: #ABB2BF"> </span><span style="color: #61AFEF">sendReminder</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75; font-style: italic">five</span><span style="color: #ABB2BF">, </span><span style="color: #E06C75; font-style: italic">context</span><span style="color: #ABB2BF">, </span><span style="color: #E06C75; font-style: italic">result</span><span style="color: #ABB2BF">) {</span></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">const</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">db</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">getDatabaseConnectionByID</span><span style="color: #ABB2BF">(</span><span style="color: #98C379">&#39;TaskMageDB&#39;</span><span style="color: #ABB2BF">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">if</span><span style="color: #ABB2BF"> (</span><span style="color: #56B6C2">!</span><span style="color: #E5C07B">db</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">isOk</span><span style="color: #ABB2BF">()) {</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #C678DD">return</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">createError</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">db</span><span style="color: #ABB2BF">, </span><span style="color: #98C379">&#39;Connect to database failed&#39;</span><span style="color: #ABB2BF">);  </span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">const</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">tx</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">startTransaction</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">db</span><span style="color: #ABB2BF">);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">if</span><span style="color: #ABB2BF"> (</span><span style="color: #56B6C2">!</span><span style="color: #E5C07B">tx</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">isOk</span><span style="color: #ABB2BF">()) {</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #C678DD">return</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">createError</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">tx</span><span style="color: #ABB2BF">, </span><span style="color: #98C379">&#39;Create transaction failed&#39;</span><span style="color: #ABB2BF">);  </span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">let</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">sqlStatement</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #98C379">&#39;Select ReminderDate From Reminders&#39;</span></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">let</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">queryResults</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">executeQuery</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">sqlStatement</span><span style="color: #ABB2BF">, </span><span style="color: #D19A66">0</span><span style="color: #ABB2BF">);</span></span>
<span class="line"><span style="color: #ABB2BF">    </span></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">if</span><span style="color: #ABB2BF"> (</span><span style="color: #56B6C2">!</span><span style="color: #E5C07B">queryResults</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">isOk</span><span style="color: #ABB2BF">()) {</span></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">createError</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">queryResults</span><span style="color: #ABB2BF">);</span></span>
<span class="line"><span style="color: #ABB2BF">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #E5C07B">queryResults</span><span style="color: #ABB2BF">.</span><span style="color: #E5C07B">values</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">map</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75; font-style: italic">item</span><span style="color: #ABB2BF"> </span><span style="color: #C678DD">=&gt;</span><span style="color: #ABB2BF"> {</span></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">log</span><span style="color: #ABB2BF">(</span><span style="color: #98C379">&quot;It works&quot;</span><span style="color: #ABB2BF">);</span></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #C678DD">let</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">currentDate</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">Date</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">now</span><span style="color: #ABB2BF">();</span></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #C678DD">let</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">reminderDate</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #C678DD">new</span><span style="color: #ABB2BF"> </span><span style="color: #61AFEF">Date</span><span style="color: #ABB2BF">(</span><span style="color: #E5C07B">item</span><span style="color: #ABB2BF">.</span><span style="color: #E06C75">ReminderDate</span><span style="color: #ABB2BF">)</span></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #C678DD">if</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">currentDate</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">&gt;=</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">reminderDate</span><span style="color: #ABB2BF">){</span></span>
<span class="line"><span style="color: #ABB2BF">            </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">showMessage</span><span style="color: #ABB2BF">(</span><span style="color: #98C379">&quot;You have a task due&quot;</span><span style="color: #ABB2BF">)</span></span>
<span class="line"><span style="color: #ABB2BF">        }</span></span>
<span class="line"><span style="color: #ABB2BF">    })</span></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">commit</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">tx</span><span style="color: #ABB2BF">)</span></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">return</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">success</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">result</span><span style="color: #ABB2BF">);</span></span>
<span class="line"><span style="color: #ABB2BF">}</span></span></code></pre></div>
<!-- /wp:kevinbatdorf/code-block-pro -->

<!-- wp:paragraph -->
<p>In the snippet above, we've appended several lines at the beginning of our existing function to establish a database connection. Initially, we utilize <code>five.getDatabaseConnectionByID()</code>, passing 'TaskMageDB' as the argument, which is the name of our database</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To confirm the name of our database, we can click on the '<strong>Data</strong>' menu, followed by '<strong>Database</strong>', which should display a list of all available databases.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>After that, we simply start a transaction using <code>five.startTransaction()</code>. Finally, just before executing our return statement, we use <code>five.commit()</code>, passing in the transaction variable, to commit our modifications. (<strong>Note</strong>: these steps are only required when we are working with Jobs in Five )</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Before proceeding, we will make one last change and that is replacing the <code>showMessage()</code> function with <code>sendNotification()</code>. Currently, we are showing a dialogue box containing our message which is not an ideal way of getting reminders so instead we will be using Five's inbuild notifications. We simply replace five.showMessage() with this:</p>
<!-- /wp:paragraph -->

<!-- wp:kevinbatdorf/code-block-pro {"code":"five.sendNotification(\u0022You have a task due\u0022)","codeHTML":"\u003cpre class=\u0022shiki one-dark-pro\u0022 style=\u0022background-color: #282c34\u0022 tabindex=\u00220\u0022\u003e\u003ccode\u003e\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003esendNotification\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026quot;You have a task due\u0026quot;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e)\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e","language":"javascript","theme":"one-dark-pro","bgColor":"#282c34","textColor":"#abb2bf","fontSize":".875rem","fontFamily":"Code-Pro-JetBrains-Mono","lineHeight":"1.25rem","headerType":"headlights","seeMoreString":"","seeMoreAfterLine":"","seeMoreTransition":false,"lineHighlightColor":"rgba(134, 167, 228, 0.2)","copyButton":true,"buttonTheme":"heroicons"} -->
<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="five.sendNotification(&quot;You have a task due&quot;)" style="color:#abb2bf;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki one-dark-pro" style="background-color: #282c34" tabindex="0"><code><span class="line"><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">sendNotification</span><span style="color: #ABB2BF">(</span><span style="color: #98C379">&quot;You have a task due&quot;</span><span style="color: #ABB2BF">)</span></span></code></pre></div>
<!-- /wp:kevinbatdorf/code-block-pro -->

<!-- wp:paragraph -->
<p>The <code>sendNotification() </code>function is designed with multiple users in mind, and thus, it expects a user key to identify the recipient of the notifications. Since we plan to use this function to send notifications to ourselves, we will need our user key.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>One method to retrieve our key is by calling the <code>five.currentUserKey()</code> method. To do this, simply invoke this method within the inspector of your browser. If you're running the local version, access the inspector by selecting '<strong>File</strong>' on the top left, followed by '<strong>Debug</strong>' in your end-user application.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1735,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://five.co/wp-content/uploads/2023/09/Frame-31-1024x572.png" alt="" class="wp-image-1735"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>We will copy this key and paste it as an argument inside our code and now our function should look like this:</p>
<!-- /wp:paragraph -->

<!-- wp:kevinbatdorf/code-block-pro {"code":"function sendReminder(five, context, result) {\n    const db = five.getDatabaseConnectionByID('TaskMageDB')\n\n    if (!db.isOk()) {\n\n        return five.createError(db, 'Connect to database failed');  \n\n    }\n\n    const tx = five.startTransaction(db);\n\n    if (!tx.isOk()) {\n\n        return five.createError(tx, 'Create transaction failed');  \n\n    }\n\n    let sqlStatement = 'Select ReminderDate From Reminders'\n    let queryResults = five.executeQuery(sqlStatement, 0);\n    if (!queryResults.isOk()) {\n        five.createError(queryResults);\n    }\n\n    queryResults.values.map(item =\u003e {\n        let currentDate = Date.now();\n        let reminderDate = new Date(item.ReminderDate)\n        if(currentDate \u003e= reminderDate){\n            five.sendNotification(\u002210000000-4444-4444-4444-000000000001\u0022,\u0022You have a task due\u0022)\n        }\n    })\n    five.commit(tx)\n    return five.success(result);\n}","codeHTML":"\u003cpre class=\u0022shiki one-dark-pro\u0022 style=\u0022background-color: #282c34\u0022 tabindex=\u00220\u0022\u003e\u003ccode\u003e\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003efunction\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003esendReminder\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75; font-style: italic\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #E06C75; font-style: italic\u0022\u003econtext\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #E06C75; font-style: italic\u0022\u003eresult\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e) {\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003econst\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003edb\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003egetDatabaseConnectionByID\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026#39;TaskMageDB\u0026#39;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e)\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003eif\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e (\u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e!\u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003edb\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eisOk\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e()) {\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003ereturn\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003ecreateError\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003edb\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026#39;Connect to database failed\u0026#39;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);  \u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    }\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003econst\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003etx\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003estartTransaction\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003edb\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003eif\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e (\u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e!\u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003etx\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eisOk\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e()) {\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003ereturn\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003ecreateError\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003etx\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026#39;Create transaction failed\u0026#39;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);  \u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    }\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003elet\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003esqlStatement\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026#39;Select ReminderDate From Reminders\u0026#39;\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003elet\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003equeryResults\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eexecuteQuery\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003esqlStatement\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #D19A66\u0022\u003e0\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003eif\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e (\u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e!\u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003equeryResults\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eisOk\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e()) {\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003ecreateError\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003equeryResults\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    }\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003equeryResults\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003evalues\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003emap\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75; font-style: italic\u0022\u003eitem\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003e=\u0026gt;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e {\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003elet\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003ecurrentDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003eDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003enow\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e();\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003elet\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003ereminderDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003enew\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003eDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003eitem\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003eReminderDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e)\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003eif\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003ecurrentDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #56B6C2\u0022\u003e\u0026gt;=\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003ereminderDate\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e){\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e            \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003esendNotification\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026quot;10000000-4444-4444-4444-000000000001\u0026quot;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e,\u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026quot;You have a task due\u0026quot;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e)\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e        }\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    })\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003ecommit\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003etx\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e)\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e    \u003c/span\u003e\u003cspan style=\u0022color: #C678DD\u0022\u003ereturn\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003efive\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #61AFEF\u0022\u003esuccess\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e(\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003eresult\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e);\u003c/span\u003e\u003c/span\u003e\n\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e}\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e","language":"javascript","theme":"one-dark-pro","bgColor":"#282c34","textColor":"#abb2bf","fontSize":".875rem","fontFamily":"Code-Pro-JetBrains-Mono","lineHeight":"1.25rem","headerType":"headlights","seeMoreString":"","seeMoreAfterLine":"","seeMoreTransition":false,"lineHighlightColor":"rgba(134, 167, 228, 0.2)","copyButton":true,"buttonTheme":"heroicons"} -->
<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="function sendReminder(five, context, result) {
    const db = five.getDatabaseConnectionByID('TaskMageDB')

    if (!db.isOk()) {

        return five.createError(db, 'Connect to database failed');  

    }

    const tx = five.startTransaction(db);

    if (!tx.isOk()) {

        return five.createError(tx, 'Create transaction failed');  

    }

    let sqlStatement = 'Select ReminderDate From Reminders'
    let queryResults = five.executeQuery(sqlStatement, 0);
    if (!queryResults.isOk()) {
        five.createError(queryResults);
    }

    queryResults.values.map(item =&gt; {
        let currentDate = Date.now();
        let reminderDate = new Date(item.ReminderDate)
        if(currentDate &gt;= reminderDate){
            five.sendNotification(&quot;10000000-4444-4444-4444-000000000001&quot;,&quot;You have a task due&quot;)
        }
    })
    five.commit(tx)
    return five.success(result);
}" style="color:#abb2bf;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki one-dark-pro" style="background-color: #282c34" tabindex="0"><code><span class="line"><span style="color: #C678DD">function</span><span style="color: #ABB2BF"> </span><span style="color: #61AFEF">sendReminder</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75; font-style: italic">five</span><span style="color: #ABB2BF">, </span><span style="color: #E06C75; font-style: italic">context</span><span style="color: #ABB2BF">, </span><span style="color: #E06C75; font-style: italic">result</span><span style="color: #ABB2BF">) {</span></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">const</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">db</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">getDatabaseConnectionByID</span><span style="color: #ABB2BF">(</span><span style="color: #98C379">&#39;TaskMageDB&#39;</span><span style="color: #ABB2BF">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">if</span><span style="color: #ABB2BF"> (</span><span style="color: #56B6C2">!</span><span style="color: #E5C07B">db</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">isOk</span><span style="color: #ABB2BF">()) {</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #C678DD">return</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">createError</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">db</span><span style="color: #ABB2BF">, </span><span style="color: #98C379">&#39;Connect to database failed&#39;</span><span style="color: #ABB2BF">);  </span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">const</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">tx</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">startTransaction</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">db</span><span style="color: #ABB2BF">);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">if</span><span style="color: #ABB2BF"> (</span><span style="color: #56B6C2">!</span><span style="color: #E5C07B">tx</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">isOk</span><span style="color: #ABB2BF">()) {</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #C678DD">return</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">createError</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">tx</span><span style="color: #ABB2BF">, </span><span style="color: #98C379">&#39;Create transaction failed&#39;</span><span style="color: #ABB2BF">);  </span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">let</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">sqlStatement</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #98C379">&#39;Select ReminderDate From Reminders&#39;</span></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">let</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">queryResults</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">executeQuery</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">sqlStatement</span><span style="color: #ABB2BF">, </span><span style="color: #D19A66">0</span><span style="color: #ABB2BF">);</span></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">if</span><span style="color: #ABB2BF"> (</span><span style="color: #56B6C2">!</span><span style="color: #E5C07B">queryResults</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">isOk</span><span style="color: #ABB2BF">()) {</span></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">createError</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">queryResults</span><span style="color: #ABB2BF">);</span></span>
<span class="line"><span style="color: #ABB2BF">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #E5C07B">queryResults</span><span style="color: #ABB2BF">.</span><span style="color: #E5C07B">values</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">map</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75; font-style: italic">item</span><span style="color: #ABB2BF"> </span><span style="color: #C678DD">=&gt;</span><span style="color: #ABB2BF"> {</span></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #C678DD">let</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">currentDate</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">Date</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">now</span><span style="color: #ABB2BF">();</span></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #C678DD">let</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">reminderDate</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">=</span><span style="color: #ABB2BF"> </span><span style="color: #C678DD">new</span><span style="color: #ABB2BF"> </span><span style="color: #61AFEF">Date</span><span style="color: #ABB2BF">(</span><span style="color: #E5C07B">item</span><span style="color: #ABB2BF">.</span><span style="color: #E06C75">ReminderDate</span><span style="color: #ABB2BF">)</span></span>
<span class="line"><span style="color: #ABB2BF">        </span><span style="color: #C678DD">if</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">currentDate</span><span style="color: #ABB2BF"> </span><span style="color: #56B6C2">&gt;=</span><span style="color: #ABB2BF"> </span><span style="color: #E06C75">reminderDate</span><span style="color: #ABB2BF">){</span></span>
<span class="line"><span style="color: #ABB2BF">            </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">sendNotification</span><span style="color: #ABB2BF">(</span><span style="color: #98C379">&quot;10000000-4444-4444-4444-000000000001&quot;</span><span style="color: #ABB2BF">,</span><span style="color: #98C379">&quot;You have a task due&quot;</span><span style="color: #ABB2BF">)</span></span>
<span class="line"><span style="color: #ABB2BF">        }</span></span>
<span class="line"><span style="color: #ABB2BF">    })</span></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">commit</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">tx</span><span style="color: #ABB2BF">)</span></span>
<span class="line"><span style="color: #ABB2BF">    </span><span style="color: #C678DD">return</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">five</span><span style="color: #ABB2BF">.</span><span style="color: #61AFEF">success</span><span style="color: #ABB2BF">(</span><span style="color: #E06C75">result</span><span style="color: #ABB2BF">);</span></span>
<span class="line"><span style="color: #ABB2BF">}</span></span></code></pre></div>
<!-- /wp:kevinbatdorf/code-block-pro -->

<!-- wp:heading -->
<h2 class="wp-block-heading">Step 3: Scheduling Our Job</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Now let's finally set up our Job to make sure the functions runs on a regular schedule.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p> Start by clicking on <strong>'Tasks'</strong> then '<strong>Jobs'</strong>. Similar to creating our <code>ReminderProcess</code>, create a new job by clicking on the yellow ‘<strong>+</strong>’ button and giving it a name. Inside the Action lookup select 'ReminderProcess' or whatever name you assigned it.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1736,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://five.co/wp-content/uploads/2023/09/Frame-21-1-1024x548.png" alt="" class="wp-image-1736"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>For testing purposes, we are going to schedule our Job to execute every minute.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Now we run our application and after 1 minute we get an alert for our notifications in the 🔔icon on the header bar.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1737,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://five.co/wp-content/uploads/2023/09/Frame-32-1-1024x190.png" alt="" class="wp-image-1737"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Clicking on the bell icon will open up our notifications. (<strong>Note</strong>: we receive 5 notifications as we have 5 tasks that are due from our Reminder Table).</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1738,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://five.co/wp-content/uploads/2023/09/Frame-28-1024x548.png" alt="" class="wp-image-1738"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Congratulations! We have successfully built a simple reminder feature for our Task Management application.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading">Conclusion</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In this Five Lab, we've navigated through the process of automating functions using Jobs in Five. Jobs lets us schedule tasks, so that they run on a regular schedule, such as every minute, every day or every week.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>We started by importing a Task Management Template to get a head start and then delved deeper into writing JavaScript functions, focusing on creating a reminder feature. We learned how to define, test, and refine our functions, ensuring they operate as intended, and how to connect them to our database, allowing for seamless interaction and data retrieval.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Moreover, we explored how to schedule our Jobs, allowing us to automate the execution of functions on a recurring basis, enhancing the efficiency and productivity of our application. </p>
<!-- /wp:paragraph -->