Using custom calculations


In this article, we introduce how to insert custom calculation results into fields.

Custom calculations are needed, when the Calculated field in kintone is not capable of achieving the calculation that you need. For example, the following calculation flow cannot be achieved by using the Calculated field in kintone:

  1. Calculating a total from a product's unit price and number.
  2. Discounting 10% if the total is more than $50.00.
  3. Discounting 20% if the total is more than $100.00.

Try the following example to calculate this using JavaScript customization.

Preparing the App

Prepare an app with the following fields.

Field Type Field Name Field Code Note
Text (single-line) Product Name Product_Name -
Number Unit Price Unit_Price -Use thousands separators
-Required Field
-Limits of Value: Minimum 0
-Number of Decimal Places:0
-Currency: $(Prefix)
Number Amount Amount -Required Field
-Limits of Value: Minimum 0
-Number of Decimal Places:0
Number Total Total -Use thousands separators
-Limits of Value: Minimum 0
-Number of Decimal Places:0
-Currency: $(Prefix)

Rewriting the value of a field

In this example, we will be using the app.record.create.submit event, the app.record.edit.submit and the app.record.index.edit.submit event that are triggered when users save their record. These events allow fields to be overwritten by changing the values inside it. Note that the change will not take effect, unless you return the event object.

When you save your record with this code in your app, the calculation should be entered into the "Total" field.


Check that the calculation and the discount is working with other calculations as well.


Disabling the Editing Function of the Total Field

For this code to be practical, we can add one more step by disabling the editing function of the total field while the record is in edit mode. The event, the event and the event have functions to disable edits.



We introduced a JavaScript customization that would calculate fields differently depending on their condition. Note that the calculations take place before any field validations take place - meaning that if text is placed instead of numbers for the number fields, this will result in an error. You can avoid this error, by having the script check the contents of the fields first, and skipping the calculation if it does not contain numbers inside.

Was this article helpful?
0 out of 0 found this helpful
Please sign in to leave a comment.