Skip to content

I want to create a new record in another table when I press the update button

Answer

Use "Script".


Overview

If you want to create a new record in another table after updating a record, you can implement this in a "Script".

Operation Procedure

  1. Create a time-limited table or recorded table
  2. Create a new "Script", enter the following script content, and set the site ID to any value (in the example below, the site ID is set to 1083). Check "Edit" for the output destination and update it.
  3. Create a new record using the [+New] button.
  4. Open the edit screen for the record created in 3 and press the [Update] button.

Execution Result

When you update a record in recorded table A, a new record is created in recorded table B.

Before update

State before the update

Update record in recorded table A

Editing screen of the record in recorded table A that is being updated

After update

State after the update, with a new record created in recorded table B

Code Samples

JavaScript
//Processing after pressing the "Update" button
$p.events.after_send_Update = function () {
    getParentData();
}

function getParentData() {
    //Create a record whose title column is "Title Test".
    $p.apiCreate({
        'id': 9999,
        'data': {
            'Offset': 0,
            'Title': 'FAQ: Sample code: Create another record after pressing the update button'
        },
        'done': function (data) {
            $p.clearMessage();
            $p.setMessage(
                '#Message', JSON.stringify({
                    'Css': 'alert-success',
                    'Text': 'A new record has been created'
                 }));
        },
        'fail': function (data) {
            console.log(data);
        }
    });
}