items.Get
Overview¶
This is the "Get Method" of the "Items Object". It gets information about the specified record or records in the specified table. If the table has "Site Integration" set, it also gets information about each integrated record.
Limitations¶
- The maximum number of records that can be retrieved is the PageSize (default 200) in Api.json. If you want to retrieve more than 200 records, please refer to FAQ: I want to retrieve data exceeding 200 records via API.
Syntax¶
Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | object | Yes | Specify the site ID and record ID |
| data | string | No | Specify the filter and sort of the records to be selected in JSON format |
Return Value¶
Return an array of "apiModel" for the corresponding records.
Usage Example 1¶
The following example retrieves the record with record ID 123.
JavaScript¶
Usage Example 2¶
The following example gets and logs information on records with a Status of 900 (completed) registered in a recorded table with a site ID of 2.
JavaScript¶
let data = {
"View": {
"ColumnFilterHash": {
"Status": "[\"900\"]"
}
}
};
let results = items.Get(2, JSON.stringify(data));
for (let item of results) {
context.Log(`${item.ResultId} ${item.Title} ${item.ClassA} ${item.NumB}`);
}
Code Samples¶
Modify 【 ... 】 in the code as necessary.¶
1. Get a record by specifying the record ID
Get a record by specifying the record ID.
JavaScript¶
// Specify the record ID and get one record
const recordId = 【Record ID】;
const results = items.Get(recordId);
logs.LogInfo(`${results[0].Title} ${results[0].ClassA}`);
Execution Result¶
2. Get all records by specifying the site ID
Get all records by specifying the site ID.
JavaScript¶
// Specify the site name and get all records
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 results = items.Get(site.SiteId);
for (const item of results) {
logs.LogInfo(`${item.Title} ${item.ClassA}`);
}
Execution Result¶
3. Get records by specifying a date range
Get records by specifying a date range.
JavaScript¶
// Specify the site name and a date range to get records
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;
}
// Specify the period to get
const start = '2025/01/10';
const end = '2025/01/12';
const data = {
View: {
ColumnFilterHash: {
DateA: `["${start} 00:00:00, ${end} 23:59:59"]`,
},
ColumnSorterHash: { DateA: 'asc' },
},
};
const results = items.Get(site.SiteId, JSON.stringify(data));
for (const item of results) {
logs.LogInfo(`${item.Title} ${item.ClassA} ${item.DateA}`);
}
Execution Result¶
4. Get records by specifying status codes
Get records by specifying the status.
JavaScript¶
// Specify the site name and status codes to get records
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 status_codes = `["100","200"]`;
const data = {
View: {
ColumnFilterHash: {
Status: `${status_codes}`,
},
ColumnSorterHash: { DateA: 'asc' },
},
};
const results = items.Get(site.SiteId, JSON.stringify(data));
for (const item of results) {
logs.LogInfo(`${item.Title} ${item.ClassA} ${item.Status}`);
}
Execution Result¶
5. Get records by searching for a string (partial match)
Get records by searching for a string (partial match).
JavaScript¶
// Specify the site name and search for a string (partial match) to get records
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 text = `release`;
const data = {
View: {
ColumnFilterHash: { DescriptionA: `${text}` },
ColumnSorterHash: { DateA: 'asc' },
ColumnFilterSearchTypes: { DescriptionA: 'PartialMatch' },
},
};
const results = items.Get(site.SiteId, JSON.stringify(data));
for (const item of results) {
logs.LogInfo(`${item.Title} ${item.ClassA} ${item.DescriptionA}`);
}
Execution Result¶
6. Get more than 200 records
Get more than 200 records.
JavaScript¶
// Specify the site name
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;
}
let offset = 0;
let totalCount = 0;
const allItems = [];
while (true) {
const data = {
Offset: offset,
};
// items.Get takes a JSON string as the second argument
const results = Array.from(
items.Get(site.SiteId, JSON.stringify(data))
);
// Stop when no more records are returned
if (!results || results.length === 0) {
break;
}
// Add the records of this round to the array
for (const item of results) {
allItems.push(item);
}
// Output a log
logs.LogInfo(`Offset=${offset}, Records retrieved=${results.length}`);
totalCount += results.length;
// Advance Offset by the number of records retrieved this time
offset += results.length;
}
logs.LogInfo(`Total records retrieved: ${totalCount}`);
// Process all the records retrieved
for (const item of allItems) {
logs.LogInfo(`${item.Title} ${item.ClassA}`);
}
Execution Result¶
(Info):Offset=0, Records retrieved=200
(Info):Offset=200, Records retrieved=150
(Info):Total records retrieved: 350
(Info):Sample project A Inquiry
(Info):Sample project B Improvement request
(Info):Sample project C Failure
(Info):Sample project D Inquiry
(Info):Sample project E Improvement request
・・・
Cautions¶
This is a method used in "Server Script". It cannot be used in "Script".