Skip to content

apiModel.Update

Overview

Update an existing record.

Syntax

apiModel.Update()

Return Value

If the record is updated, true is returned; if not, false is returned.

Usage Examples

The following example gets the record information for record ID 123 and updates the "Status Column" to completed (900).

JavaScript
let records = items.Get(123);
if (records.Length === 1) {
    let record = records[0];
    record.Status = 900;
    record.Update();
}
Modify 【 ... 】 in the code as necessary.
1. Get the records that meet a given condition and update a column in bulk

Get the records whose status is '100' and update them to '200'.

JavaScript
// Target the records whose status is Not started (100)
const targetStatus = '100';
// Update them to In progress (200)
const updateStatus = '200';
// Specify the name of the site to process
const siteName = '【Site name】';
// Get the site information
const site = items.GetClosestSite(siteName);
if (!site) {
    logs.LogInfo(`${siteName} Failed to get the site information`);
    return false;
}
const data = {
    View: {
        ColumnFilterHash: {
            Status: `[\"${targetStatus}\"]`,
        },
    },
};
const results = Array.from(items.Get(site.SiteId, JSON.stringify(data)));
// Update the status of the records found
for (const item of results) {
    item.Status = updateStatus;
    const result = item.Update();
    if (result) {
        logs.LogInfo(`Update succeeded: Id=${item.ResultId}`);
    } else {
        logs.LogUserError(`Update failed: Id=${item.ResultId}`);
    }
}
Execution Result
(Info):Update succeeded: Id=9001
(Info):Update succeeded: Id=9002

Cautions

This is a method used in "Server Script". It cannot be used in "Script".