Introduction
User Selection fields in Kintone can hold information of multiple users. The number of users that can be selected for the value though cannot be controlled with Kintone's built-in features.
There are some cases though where we would like to use the User Selection field for selecting managers or ticket requestors, and those fields should usually only consist of one user.
This issue can be solved by using some JavaScript customization.
This article introduces a customization to allow only one user to be selected in the User selection field.
App Setup
Prepare the App where you would like to apply the customization. The only field needed for this customization to run is the User Selection field, so make sure this field is included, and take note of the field code.
Source Code
Code Explanation
- Events need to be set for pages where fields can be edited - the Record Create, Record Edit and Record List pages. Make sure to list all related events in the code:
-app.record.create.submit
-app.record.edit.submit
-app.record.index.edit.submit
- The User Selection field holds values in an array. If the length of the array is 2 or more, the code places an error message inside event.error and returns the event object.
Test the Customization
Apply this source code to the Kintone App prepared in the previous steps.
Try specifying 2 or more users in the User Selection field on the Record Create page, Record Edit page and the Record List page. If successful, and error message will appear, and the user will not be able to save the record.