diff --git a/packages/basic.gblib/services/KeywordsExpressions.ts b/packages/basic.gblib/services/KeywordsExpressions.ts index ac2d2387..ba770f2e 100644 --- a/packages/basic.gblib/services/KeywordsExpressions.ts +++ b/packages/basic.gblib/services/KeywordsExpressions.ts @@ -1003,7 +1003,7 @@ export class KeywordsExpressions { $4 = $4.substr(2); const fields = $4.split(','). - return `await sys.save({pid: pid, file: "${$3}", args: [${$4}]}, fields)`; + return `await sys.saveToStorage({pid: pid, file: "${$3}", args: [${$4}]}, fields)`; } ]; diff --git a/packages/basic.gblib/services/SystemKeywords.ts b/packages/basic.gblib/services/SystemKeywords.ts index fe3fae95..c83dc68c 100644 --- a/packages/basic.gblib/services/SystemKeywords.ts +++ b/packages/basic.gblib/services/SystemKeywords.ts @@ -640,13 +640,42 @@ export class SystemKeywords { /** * Takes note inside a notes.xlsx of .gbdata. * - * @exaple NOTE "text" + * @example NOTE "text" * */ public async note({ pid, text }): Promise { await this.save({pid, file:"Notes.xlsx", args:[text]} ); } + /** + * Saves variables to storage, not a worksheet. + * + * @example SAVE "Billing", columnName1, columnName2 + * + */ + public async saveToStorage({pid, table, fields, fieldsNames}){ + + const fieldRegExp = /(?:.*\.)(.*)/gim; + const minBoot = GBServer.globals.minBoot as any; + const definition = minBoot.core.sequelize.models[table]; + + let data = {}; + let index = 0; + + fields.forEach(field => { + + // Extracts only the last part of the variable like 'column' + // from 'row.column'. + + let name = fieldsNames[index]; + name = fieldRegExp.exec(name)[2]; + + data[name] = field; + }); + + return await definition.create(data); + } + /** * Saves the content of several variables to a new row in a tabular file. *