User Manual

12.27.2024

MANUAL

Developer Function: Server Script: items.Upsert

## Overview If a record corresponding to a key column exists at the specified site, it is updated; if not, a new record is created. ## Limitations 1. The ID of the created or updated record cannot be retrieved from the return value of items.Upsert or from the variables used in items.Upsert. ## Syntax ``` items.Upsert(siteId, json) ``` ## Parameters |Parameter|Type|Required|Description| |:----------|:----------|:---:|:---------------------------| |siteId|object|Yes|Specify the site ID| |json|string|Yes|Specify the JSON string| #### About the Specified Key Column The API creates and updates (upsert) records based on the specified key columns. Key columns are specified by the following parameters. |Property name|Data type|Description| |:--|:--|:--| |Keys|Array (string)|Specify the key columns. Multiple columns can be specified. | ## Return Value If the record was updated or a new record was created, true is returned; if not, false is returned. ## Usage Example 1 In the example below, the key column is set to "ClassA" and the table with site ID 123 is updated if the corresponding record ("Ubuntu" for ClassA) exists; if not, a new record is created. The information to update or create a new record is as follows: ・Title: How to Install Pleasanter ・Status: Running (200) ・ClassA: Ubuntu ・ClassB: PostgreSQL ##### JavaScript ``` let data = { Keys: ["ClassA"], Title: "How to Install Pleasanter", Status: 200, ClassHash: { ClassA: "Ubuntu", ClassB: "PostgreSQL" } }; items.Upsert(123, JSON.stringify(data)); ``` ## Usage Example 2 In the example below, the key column is the title, and if the corresponding record (with title "Sample") for site ID 123 exists, it is updated; if not, a new record is created. In this case, the value entered in DateA is transcribed to DateC. __Date column is treated as UTC in the server script, so please convert them appropriately.__ ##### JavaScript ``` let date = model.DateA; let jstDate = date.toLocaleString("ja-JP",{ timeZone: "JST" }); let data = { Keys: ["Title"], Title: "Sample", DateHash: { DateC: jstDate } }; items.Upsert(123, JSON.stringify(data)); ``` ## Related Information ・[Manage Table: Server Script](/manual/table-management-server-script) ・[Items Object](/manual/server-script-items) ・[Developer Function: API: Table Operation: Create/Update Record](/manual/api-record-upsert)
TOP
このページをシェアする
記載された商品名、各製品名は各社の登録商標または商標です。 © Implem Inc.