apiModel.Delete
Overview¶
Delete an existing record.
Syntax¶
Return Value¶
If the record is deleted, it returns true; if not, it returns false.
Usage Examples¶
The following example deletes the record with record ID 123.
JavaScript¶
let records = items.Get(123);
if (records.Length === 1) {
let record = records[0];
record.Delete();
}
Code Samples¶
Modify 【 ... 】 in the code as necessary.¶
1. Delete the records that meet a given condition
Get the records whose status is '910' and delete them.
JavaScript¶
// Target the records whose status is On hold (910)
const targetStatus = '910';
// 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 = items.Get(site.SiteId, JSON.stringify(data));
// Delete the records found
for (const item of results) {
const result = item.Delete();
if (result) {
logs.LogInfo(`Delete succeeded: Id=${item.ResultId}`);
} else {
logs.LogUserError(`Delete failed: Id=${item.ResultId}`);
}
}
Execution Result¶
Cautions¶
This is a method used in "Server Script". It cannot be used in "Script".