n8n-nodes-smartsuite
Version:
n8n community node for SmartSuite
42 lines • 2.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.execute = execute;
const n8n_workflow_1 = require("n8n-workflow");
const utils_1 = require("../../helpers/utils");
const smartSuiteApi_1 = require("../../transport/smartSuiteApi");
const validation_1 = require("../../helpers/validation");
async function execute() {
const solutionId = await validation_1.getSolutionId.call(this, 0);
const tableId = await validation_1.getTableId.call(this, 0);
(0, utils_1.debugLog)('[Record] updateRecord.execute called', this.getNode().parameters, 2);
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
const recordId = this.getNodeParameter('recordId', i);
if (!recordId.trim()) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Record ID is required for Update Record operation.', { itemIndex: i });
}
const fieldsArr = this.getNodeParameter('fieldsUiUpdate.fieldsValues', i, []);
if (!fieldsArr.length) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'You must provide at least one field to update a record.', { itemIndex: i });
}
// Prevent updating system fields
for (const { field } of fieldsArr) {
const slug = (0, utils_1.asIdString)(field);
if ((0, utils_1.isReservedField)(slug)) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Cannot update system field “${slug}”.`, { itemIndex: i });
}
}
// Build request payload
const payload = fieldsArr.reduce((obj, { field, value }) => {
obj[(0, utils_1.asIdString)(field)] = value;
return obj;
}, {});
(0, utils_1.debugLog)('[Record] updateRecord.request', { solutionId, tableId, recordId, payload }, 2);
const response = (await smartSuiteApi_1.apiRequest.call(this, 'PATCH', `/applications/${tableId}/records/${recordId}/`, payload));
(0, utils_1.debugLog)('[Record] updateRecord.response', response, 2);
returnData.push(...this.helpers.returnJsonArray([response]));
}
return returnData;
}
//# sourceMappingURL=updateRecord.operation.js.map