generated from ahandsel/Kintone_Customization_Webpack
-
Notifications
You must be signed in to change notification settings - Fork 11
/
getRecords.js
34 lines (27 loc) · 1007 Bytes
/
getRecords.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// getRecords.js - Fetches Kintone records, transforms response, & returns array of objects per record
/**
* Notes on Kintone responses:
* record.title.value = value of the Title field
* record.author.value = value of the Author field
* record.$id.value = value of the Record number field (unique key for the record)
*/
export default async function getRecords() {
const body = {
'app': kintone.app.getId(),
'query': 'order by $id asc'
};
const resp = await kintone.api(kintone.api.url('/k/v1/records', true), 'GET', body
);
let listItemArray = [];
let respRecords = resp.records; // array of records (objects)
listItemArray = respRecords.map(function (record) {
return {
uniqueKey: record.$id.value, // $id = Automatically generated Record ID
author: record.author.value,
title: record.title.value
}
});
console.log('listItemArray: \n', listItemArray);
// Used in setListItems() and setSearchResults() in index.js
return listItemArray;
};