Auto-assign a user when adding a record

In the process management options of a kintone App, you may have noticed that you can only auto-assign the creator of the record when a record is created. This sample code initiates the Update Assignees API after the record is added, and automatically assigns the first person listed in the User Selection field.

Sample Image

autoassign.gif

Sample Code

(function() {
    "use strict";
    var USERIDDATA = "employee";    //the field code of the User selection field

    //Updates the assignee to the first person listed in the User selection field, after adding a record.
    kintone.events.on("app.record.create.submit.success", function(e) {
        var appid = e.appId;
        var record = e.record;
        var body = {
            "app": appid,
            "id": record['$id'].value,
            "assignees": [record[USERIDDATA].value[0].code]
        };

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

Notes

Refer to the Tutorial page, on how to add scripts to your app.
The Process Management Settings for the App must be turned on for this code to run.
This sample only assigns the first user listed in the user selection field. Any other users will be ignoered.

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