Send Purchase Order Confirmation Emails from Records
Overview
This article introduces how to send emails from Kintone records using Zapier and Gmail. In addition to a Kintone environment, the following will also need to be prepared:
- A Gmail account to act as the email sender
- A Zapier account that allows multi-step and premium Apps (refer to Zapier's Plans & Pricing page for details)
Sample image
The overall solution will operate as follows.
- When the process management status of a record in a Purchase Order Management App proceeds to Order confirmed, a record is created in an Email Sent Log App with the format for the order details that will be sent by email.
- Creating a record in the Email Sent Log App triggers a Zapier Zap that sends an email with the order details.
- After the email is sent, the next step in the Zap updates the process management status of the Purchase Order Management App record to Confirmation email sent.
Prepare the Purchase Order Management App
This tutorial uses two Kintone Apps: a Purchase Order Management App to manage orders from customers, and an Email Sent Log App to keep a record of confirmation emails sent.
This section describes how to prepare the Purchase Order Management App.
Create the Form
Create an App with the following field and settings. Save the form when finished.
Field Type | Field Name | Field Code | Notes |
---|---|---|---|
Text | Tracking No. | tracking_no | - |
Text | Customer name | customer_name | - |
Link | Customer email address | email_address | Set to E-mail address |
Table | Items | items | See the table below for the fields to place inside. |
Calculated | Total | total |
|
Record number | Record number | Record_number | - |
Created datetime | Created datetime | Created_datetime | - |
Blank space | - | - | Used to position the Total field |
Set the following fields and settings for the Table field.
Field Type | Field Name | Field Code | Notes |
---|---|---|---|
Text | Item name | item_name | Part of the Items table |
Number | Unit price | unit_price |
|
Number | Quantity | quantity | Use thousands separators: Checked |
Calculated | Subtotal | subtotal |
|
The form should look like the following:
Note
Item name, Unit price, Quantity, and Subtotal are within a Table field called Items. Refer to the Adding Tables into Forms article from the Kintone Help Center for details on creating Table fields.
Set the Process Management Settings
Open the App Settings tab and navigate to Process Management under General Settings.
Check the Enable process management check box to enable the process management feature.
Set Process Management settings
with the following. Note that the status names will be used in the code, and they are case-sensitive.
- Status
Order received, Order confirmed, Confirmation email sent, Shipped, Arrived, Suspended
Under Process Flow Settings, set up the flow like the following.
- Process list
Status Assignee Action Next Status Order received Set to anybody - Confirm order
- Suspend
- Order confirmed
- Suspended
Order confirmed - Set confirmation email Confirmation email sent Confirmation email sent - Product shipped Shipped Shipped - Product arrived Arrived Suspended - Prepare order Order confirmed
Generate an API Token
Open the App Settings tab and click API Token under Customization and Integration.
Click the Generate button and check Edit records. Then save the settings.
Make a note of the generated API token, as it will be necessary later for the customization code. Also make a note the App ID (in the following sample application, the App ID is 7).
Prepare the Email Sent Log App
Create an App with the following field and settings. Save the form when finished.
Field Type | Field Name | Field Code | Notes |
---|---|---|---|
Text | Tracking No. | tracking_no | - |
Number | Purchase Order Record No. | po_record_no | - |
Created datetime | Email sent time | email_sent_time | - |
Link | Customer email address | email_address | Set to E-mail address |
Text | Email subject | email_subject | - |
Rich text | Email body | email_body | - |
Border | - | - | Used to break up form details, optional |
Sample Code
In the Purchase Order Management App, prepare the following JavaScript code in a text editor and navigate to the Kintone App's settings. Upload the file into the Upload JavaScript for PC option of the
JavaScript and CSS Customization settings
.
On line 44, replace EMAIL_SENT_LOG_APP_ID
with the App ID of the created Email Sent Log App. The App ID is the number that appears after the /k/ in the URL of the App. For example, in the case of https://example.kintone.com/k/35,the App ID is 35.
|
|
Save the settings and update the App.
Test out the customization by creating a new record in the Purchase Order Management App and proceeding the process management status to Order confirmed. This test record will be used later on in the Zapier set up so make sure that the Customer email address field is either a personally accessible email address or a dummy address. Check the Email Sent Log App to confirm that a new record has been created with details from the record in the Purchase Order Management App.
Below is a sample screenshot of the Purchase Order Management App record:
Below is a sample screenshot of the Email Sent Log App record:
Set Up the Zapier Zap
Log in to Zapier and click the Make A Zap button to start the Zap set up. Give the Zap a name.
Set Up the Add Record Trigger
In the search box under Choose App & Event, type in Webhook and select Webhooks by Zapier. As a side note, while a Kintone app for Zapier exists, the Add Record trigger cannot retrieve Rich text field data. Therefore, in order to retrieve the email body content held within the Rich text field, it is necessary to use a webhook as the Zap trigger instead.
The App and Trigger Event will be displayed. Select Webhooks by Zapier for the App, and Catch Hook for the Trigger Event. Click Continue.
The Customize Request settings will display a Webhook URL. Copy this URL. Other settings may be left as is.
Navigate back to Kintone on a different browser tab and access the settings of the Email Sent Log App. Click on the App Settings tab and click on Webhooks. Click the [+] button to create a new Webhook setting. Under Description, give the Webhook setting an appropriate title. Paste the copied URL from Zapier into the URL field. Under Events, select Record is added. When complete, click Save to save the settings and then update the App.
Back in Zapier, click Continue. The next setting will test to see if the webhook from the Kintone record will be caught by Zapier. Navigate back to Kintone, and create a new record in the Purchase Order Management App. Proceed the process management to Order confirmed. This should create a new record in the Email Sent Log App, which will send a webhook to Zapier. If the test was successful, the data of the created record in the Email Sent Log App should be retrieved and shown in Zapier.
Click Continue.
Set Up the Send Email Action
Set up the action that will be executed after the trigger. In this case, Gmail will be used to send the email data.
In the Choose App & Event field, enter in Gmail and select the Gmail icon.
Select Send Email as the action event from the drop down box.
Click Continue. In the Choose Account settings, if the appropriate Gmail account is already linked, select that account from the drop down. If not, click Add a New Account, and link the necessary Gmail account. Once added and selected, click Continue.
The next step is to map the Kintone data from the retrieved record to the data needed to send the email. Fields can be filled with either manually inserted text or with a variable from the Kintone form. The drop down will show field types as well as field values, so be careful to select the appropriate value. Also note that the field value shown is just to aid in setup to see what the actual value will look like, and is only used to template the form.
For example, the To field should contain the email address of the customer. From the drop down menu, both the email address field type and the value can be selected, so it's necessary to make sure that the value is selected as shown below.
All the Zapier field mappings and field settings are as follows:
Field Name | Field Value |
---|---|
To | Record Email Address Value |
From | Linked Gmail Account |
From Name (optional) | Optional |
Subject | Record Email Subject Value |
Body Type | HTML |
Body | Record Email Body Value |
Click Continue and test the action. An email with the mapped values will be sent to the email address set in the To field.
Set Up the Edit Record Action
Click the [+] button below the completed step to add a new step to the Zap.
This will add an additional step to the Zap that will be activated when the Gmail email is successfully sent. In the search box, enter Kintone. Select the Kintone App when it appears.
In the next settings, select Update Status from the dropdown menu as the action event. This action event will be used to update the status of the Purchase Order Management App record from Order confirmed to Confirmation email sent. Click Continue.
From the Kintone account dropdown, select Add a new account. A pop-up will appear asking for details of the Kintone account and the App ID and API token of the App whose records will be edited. Fill in the details and be careful to read the explanations of each field carefully. The API token is the token that was generated when creating the Purchase Order Management App. An example of the form is shown below.
Click Yes, Continue in the pop up to save the settings, and then click Continue in the main Zapier setup page to continue.
The next settings will set up the status update settings. Set the Record ID field as the Record ID of the Purchase Order Management App record to update. Since the Email Sent Log App contains the Record ID of the original Purchase Order Management App record, it is accessible through the data that was obtained with the webhook. From the drop down menu, select Catch Hook, and then Record Po Record No Value. Be careful to select the Record ID that corresponds to the Purchase Order Management App record, and not the Record ID of the Email Sent Log App record.
Since there is no assignee in the process management settings, the Log in Name of Assignee field can be omitted. For Action Name, manually add in Sent confirmation email. The completed setup is shown below.
Click Continue and test the action. If the action is successful, then the Zap is complete. Turn on the Zap and test the entire solution with a personal email and dummy data. A sample of the sent email is shown below.
The record status The Purchase Order Management App should also be automatically updated to Confirmation email sent.
Code Explanation
This section will explain the sample code used in the Purchase Order Management App.
Since the code should run only when the status of a record reaches the Order confirmed status, the Update Status Event is set up to run the main code in the handler if the next status is Order confirmed.
|
|
This section of the sample code declare the values necessary for the email template. The string itemsTable is declared to hold the HTML table element that contains the items from the Items table of the record. A forEach loop is used to iterate over each item in the record table and insert the generated table row element into the itemsTable string.
|
|
The string emailBody is then declared to contain the HTML template of the email. The values declared in the previous section are inserted into the template.
|
|
Finally, the post body for a Kintone REST API Request is created, containing the values necessary to create an Email Sent Log App record. The Kintone API method is then declared and the REST API is executed to create a new record in the Email Sent Log App with the details from the Purchase Order Management App record.
|
|
Reference
Note
Kintone is not affiliated with Zapier and technical support for Zapier integrations with Kintone cannot be provided.