Auto-assign Users when Adding Records

Contents

Overview

This article introduces how to auto-assign a user in a Kintone App's record, after the record has been added. With Kintone's default features, only the creator of the record can be auto-assigned.

Sample Image

When a new record is added, the Update Status API is called. It uses the value saved in the User selection field, proceeds to the next status, and assigns that user.

Prepare the App

Create the form

Create an App (External link) with the following fields and settings.

Field Type Field Name Field Code Notes
User Selection Approver Approver
User Selection Employee Employee This field is used for Process Management.

Place any other fields in this App.

Set the process management settings

The Process Management Settings for the App must be enabled for this code to run.
In the settings of the App, navigate to App Settings, then to Process Management. Check the "Enable process management" checkbox. Make any necessary updates to the Status Settings option. For the Process Flow Settings, navigate to the row that includes the status that comes after the default status. Choose Add a field for selection, and then select the User Selection field that will contain the user that will be auto-assigned.

Save the settings, and click on Update App to apply the changes to the Kintone App.

Example Settings when assigning only 1 user

Set Process Management settings (External link) with the following.

  • Status
    Before submission (Draft), Submitted, Approved, Send back

  • Process list

    Status Assignee Action Next Status
    Before submission (Draft) Created by Submit Submitted
    Submitted User chooses one assignee from the list to take action: Approver
    • Approve
    • Send back
    • Approved
    • Sent back
    Sent back User chooses one assignee from the list to take action: Employee Re-submit Submitted

Example settings when assigning multiple users

Set Process Management settings (External link) with the following.

  • Status
    Before submission (Draft), Submitted, Approved, Send back

  • Process list
    Status Assignee Action Next Status
    Before submission (Draft) Created by Submit Submitted
    Submitted One assignee in the list must take action: Approver
    • Approve
    • Send back
    • Approved
    • Sent back
    Sent back User chooses one assignee from the list to take action: Employee Re-submit Submitted

Sample Code

If assigning only 1 user

This sample code assigns the first user listed in the User Selection field.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(function() {
  'use strict';
  var USERIDDATA = 'Approver'; // The field code of the User selection field
  console.log(USERIDDATA);

  /* Updates the assignee to the first person listed in the User selection field
    after adding a record and changes the status to the next status.*/
  kintone.events.on('app.record.create.submit.success', function(event) {
    var appid = event.appId;
    var record = event.record;
    var body = {
      'app': appid,
      'id': record.$id.value,
      'action': 'Submit', // Name of the action on the button to submit to the next status
      'assignee': record[USERIDDATA].value[0].code
    };
    return kintone.api(kintone.api.url('/k/v1/record/status.json', true), 'PUT', body).then(function(resp) {
      // success
      return resp;
    }, function(error) {
      // error
      console.log(error);
    });
  });
})();

If assigning multiple users

This sample code assigns all users listed in the User Selection field. In the Process Management settings, set the "Assignee List" of the status to "All assignees in the list must take action".

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
(function() {
  'use strict';
  /* Updates the assignee to the first person listed in the User selection field
    after adding a record and changes the status to the next status.*/
  kintone.events.on('app.record.create.submit.success', function(event) {
    var appid = event.appId;
    var record = event.record;
    var body = {
      'app': appid,
      'id': record.$id.value,
      'action': 'Submit', // Name of the action on the button to submit to the next status
    };

    return kintone.api(kintone.api.url('/k/v1/record/status.json', true), 'PUT', body).then(function(resp) {
      // success
      return resp;
    }, function(error) {
      // error
      console.log(error);
    });
  });
})();