Add option to use Field IDs on Quickbase Node (#1651)

* QuickBase: Use FieldIDs instead of names

* Fix name change

* Delete tmp-209473KO4eyCT5LSi

* Fix name change

* Change default to false
This commit is contained in:
Colton Anglin 2021-04-30 21:48:40 -05:00 committed by GitHub
parent 03639b0e3a
commit 35cae02a36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 77 deletions

View file

@ -41,8 +41,10 @@ export async function quickbaseApiRequest(this: IExecuteFunctions | ILoadOptions
body, body,
qs, qs,
uri: `https://api.quickbase.com/v1${resource}`, uri: `https://api.quickbase.com/v1${resource}`,
json: true, json: true
}; };
if (Object.keys(body).length === 0) { if (Object.keys(body).length === 0) {
delete options.body; delete options.body;
} }

View file

@ -230,8 +230,8 @@ export class QuickBase implements INodeType {
if (operation === 'create') { if (operation === 'create') {
const tableId = this.getNodeParameter('tableId', 0) as string; const tableId = this.getNodeParameter('tableId', 0) as string;
const { fieldsLabelKey, fieldsIdKey } = await getFieldsObject.call(this, tableId); const useFieldIDs = this.getNodeParameter('useFieldIDs', 0) as boolean;
const simple = this.getNodeParameter('simple', 0) as boolean; const simple = this.getNodeParameter('simple', 0) as boolean;
const data: IDataObject[] = []; const data: IDataObject[] = [];
@ -244,10 +244,16 @@ export class QuickBase implements INodeType {
const columns = this.getNodeParameter('columns', i) as string; const columns = this.getNodeParameter('columns', i) as string;
const columnList = columns.split(',').map(column => column.trim()); const columnList = columns.split(',').map(column => column.trim());
if (useFieldIDs) {
for (const key of Object.keys(items[i].json)) { for (const key of Object.keys(items[i].json)) {
if (fieldsLabelKey.hasOwnProperty(key) && columnList.includes(key)) { record[key] = { value: items[i].json[key] };
record[fieldsLabelKey[key].toString()] = { value: items[i].json[key] }; }
} else {
const { fieldsLabelKey } = await getFieldsObject.call(this, tableId);
for (const key of Object.keys(items[i].json)) {
if (fieldsLabelKey.hasOwnProperty(key) && columnList.includes(key)) {
record[fieldsLabelKey[key].toString()] = { value: items[i].json[key] };
}
} }
} }
@ -259,8 +265,9 @@ export class QuickBase implements INodeType {
to: tableId, to: tableId,
}; };
// If not fields are set return at least the record id // If no fields are set return at least the record id
body.fieldsToReturn = [fieldsLabelKey['Record ID#']]; // 3 == Default Quickbase RecordID #
body.fieldsToReturn = [3];
if (options.fields) { if (options.fields) {
body.fieldsToReturn = options.fields as string[]; body.fieldsToReturn = options.fields as string[];
@ -275,7 +282,7 @@ export class QuickBase implements INodeType {
for (const record of records) { for (const record of records) {
const data: IDataObject = {}; const data: IDataObject = {};
for (const [key, value] of Object.entries(record)) { for (const [key, value] of Object.entries(record)) {
data[fieldsIdKey[key]] = (value as IDataObject).value; data[key] = (value as IDataObject).value;
} }
responseData.push(data); responseData.push(data);
} }
@ -365,6 +372,8 @@ export class QuickBase implements INodeType {
const { fieldsLabelKey, fieldsIdKey } = await getFieldsObject.call(this, tableId); const { fieldsLabelKey, fieldsIdKey } = await getFieldsObject.call(this, tableId);
const useFieldIDs = this.getNodeParameter('useFieldIDs', 0) as boolean;
const simple = this.getNodeParameter('simple', 0) as boolean; const simple = this.getNodeParameter('simple', 0) as boolean;
const updateKey = this.getNodeParameter('updateKey', 0) as string; const updateKey = this.getNodeParameter('updateKey', 0) as string;
@ -380,9 +389,16 @@ export class QuickBase implements INodeType {
const columnList = columns.split(',').map(column => column.trim()); const columnList = columns.split(',').map(column => column.trim());
for (const key of Object.keys(items[i].json)) { if (useFieldIDs) {
if (fieldsLabelKey.hasOwnProperty(key) && columnList.includes(key)) { for (const key of Object.keys(items[i].json)) {
record[fieldsLabelKey[key].toString()] = { value: items[i].json[key] }; record[key] = { value: items[i].json[key] };
}
} else {
const { fieldsLabelKey } = await getFieldsObject.call(this, tableId);
for (const key of Object.keys(items[i].json)) {
if (fieldsLabelKey.hasOwnProperty(key) && columnList.includes(key)) {
record[fieldsLabelKey[key].toString()] = { value: items[i].json[key] };
}
} }
} }
@ -390,8 +406,6 @@ export class QuickBase implements INodeType {
throw new NodeOperationError(this.getNode(), `The update key ${updateKey} could not be found in the input`); throw new NodeOperationError(this.getNode(), `The update key ${updateKey} could not be found in the input`);
} }
record[fieldsLabelKey['Record ID#']] = { value: items[i].json[updateKey] };
data.push(record); data.push(record);
} }
@ -400,8 +414,9 @@ export class QuickBase implements INodeType {
to: tableId, to: tableId,
}; };
// If not fields are set return at least the record id // If no fields are set return at least the record id
body.fieldsToReturn = [fieldsLabelKey['Record ID#']]; // 3 == Default Quickbase RecordID #
//body.fieldsToReturn = [fieldsLabelKey['Record ID#']];
if (options.fields) { if (options.fields) {
body.fieldsToReturn = options.fields as string[]; body.fieldsToReturn = options.fields as string[];
@ -432,7 +447,8 @@ export class QuickBase implements INodeType {
if (operation === 'upsert') { if (operation === 'upsert') {
const tableId = this.getNodeParameter('tableId', 0) as string; const tableId = this.getNodeParameter('tableId', 0) as string;
const { fieldsLabelKey, fieldsIdKey } = await getFieldsObject.call(this, tableId); const useFieldIDs = this.getNodeParameter('useFieldIDs', 0) as boolean;
const simple = this.getNodeParameter('simple', 0) as boolean; const simple = this.getNodeParameter('simple', 0) as boolean;
@ -451,9 +467,16 @@ export class QuickBase implements INodeType {
const columnList = columns.split(',').map(column => column.trim()); const columnList = columns.split(',').map(column => column.trim());
for (const key of Object.keys(items[i].json)) { if (useFieldIDs) {
if (fieldsLabelKey.hasOwnProperty(key) && columnList.includes(key)) { for (const key of Object.keys(items[i].json)) {
record[fieldsLabelKey[key].toString()] = { value: items[i].json[key] }; record[key] = { value: items[i].json[key] };
}
} else {
const { fieldsLabelKey } = await getFieldsObject.call(this, tableId);
for (const key of Object.keys(items[i].json)) {
if (fieldsLabelKey.hasOwnProperty(key) && columnList.includes(key)) {
record[fieldsLabelKey[key].toString()] = { value: items[i].json[key] };
}
} }
} }
@ -472,8 +495,9 @@ export class QuickBase implements INodeType {
mergeFieldId, mergeFieldId,
}; };
// If not fields are set return at least the record id // If no fields are set return at least the record id
body.fieldsToReturn = [fieldsLabelKey['Record ID#']]; // 3 == Default Quickbase RecordID #
body.fieldsToReturn = [3];
if (options.fields) { if (options.fields) {
body.fieldsToReturn = options.fields as string[]; body.fieldsToReturn = options.fields as string[];
@ -488,7 +512,7 @@ export class QuickBase implements INodeType {
for (const record of records) { for (const record of records) {
const data: IDataObject = {}; const data: IDataObject = {};
for (const [key, value] of Object.entries(record)) { for (const [key, value] of Object.entries(record)) {
data[fieldsIdKey[key]] = (value as IDataObject).value; data[key] = (value as IDataObject).value;
} }
responseData.push(data); responseData.push(data);
} }

View file

@ -69,7 +69,7 @@ export const recordFields = [
description: 'The table identifier', description: 'The table identifier',
}, },
{ {
displayName: 'Columns', displayName: 'Insert Fields',
name: 'columns', name: 'columns',
type: 'string', type: 'string',
displayOptions: { displayOptions: {
@ -84,11 +84,30 @@ export const recordFields = [
}, },
default: '', default: '',
required: true, required: true,
placeholder: 'id,name,description', placeholder: 'Select Fields...',
description: 'Comma separated list of the properties which should used as columns for the new rows.', description: 'Comma separated list of the properties which should used as columns for the new rows.',
}, },
{ {
displayName: 'Simple', displayName: 'Use Field IDs',
name: 'useFieldIDs',
type: 'boolean',
displayOptions: {
show: {
resource: [
'record',
],
operation: [
'create',
'upsert',
'update'
],
},
},
default: false,
description: 'Use Field IDs instead of Field Names in Insert Fields.',
},
{
displayName: 'Simplified Response',
name: 'simple', name: 'simple',
type: 'boolean', type: 'boolean',
displayOptions: { displayOptions: {
@ -122,7 +141,7 @@ export const recordFields = [
}, },
options: [ options: [
{ {
displayName: 'Fields', displayName: 'Return Fields',
name: 'fields', name: 'fields',
type: 'multiOptions', type: 'multiOptions',
typeOptions: { typeOptions: {
@ -133,7 +152,7 @@ export const recordFields = [
}, },
default: [], default: [],
description: `Specify an array of field ids that will return data for any updates or added record. Record ID (FID 3) is always returned if any field ID is requested.`, description: `Specify an array of field ids that will return data for any updates or added record. Record ID (FID 3) is always returned if any field ID is requested.`,
}, }
], ],
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -255,54 +274,6 @@ export const recordFields = [
}, },
}, },
options: [ options: [
// {
// displayName: 'Group By',
// name: 'groupByUi',
// placeholder: 'Add Group By',
// type: 'fixedCollection',
// typeOptions: {
// multipleValues: true,
// },
// default: {},
// options: [
// {
// name: 'groupByValues',
// displayName: 'Group By',
// values: [
// {
// displayName: 'Field ID',
// name: 'fieldId',
// type: 'options',
// typeOptions: {
// loadOptionsMethod: 'getTableFields',
// },
// default: '',
// description: 'The unique identifier of a field in a table.',
// },
// {
// displayName: 'Grouping',
// name: 'grouping',
// type: 'options',
// options: [
// {
// name: 'ASC',
// value: 'ASC',
// },
// {
// name: 'DESC',
// value: 'DESC',
// },
// {
// name: 'Equal Values',
// value: 'equal-values',
// },
// ],
// default: 'ASC',
// },
// ],
// },
// ],
// },
{ {
displayName: 'Select', displayName: 'Select',
name: 'select', name: 'select',