mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-05 22:38:48 +00:00
BugFix: variables not accessible from custom js queries (#2448)
This commit is contained in:
parent
5a8e7f72f1
commit
b2491a05d2
2 changed files with 23 additions and 4 deletions
|
|
@ -72,13 +72,24 @@ export function getDataFromLocalStorage(key) {
|
|||
|
||||
export function runTransformation(_ref, rawData, transformation, query) {
|
||||
const data = rawData;
|
||||
const evalFunction = Function(['data', 'moment', '_', 'components', 'queries', 'globals'], transformation);
|
||||
const evalFunction = Function(
|
||||
['data', 'moment', '_', 'components', 'queries', 'globals', 'variables'],
|
||||
transformation
|
||||
);
|
||||
let result = [];
|
||||
|
||||
const currentState = _ref.state.currentState || {};
|
||||
|
||||
try {
|
||||
result = evalFunction(data, moment, _, currentState.components, currentState.queries, currentState.globals);
|
||||
result = evalFunction(
|
||||
data,
|
||||
moment,
|
||||
_,
|
||||
currentState.components,
|
||||
currentState.queries,
|
||||
currentState.globals,
|
||||
currentState.variables
|
||||
);
|
||||
} catch (err) {
|
||||
console.log('Transformation failed for query: ', query.name, err);
|
||||
result = { message: err.stack.split('\n')[0], status: 'failed', data: data };
|
||||
|
|
|
|||
|
|
@ -274,10 +274,18 @@ export async function executeMultilineJS(currentState, code) {
|
|||
|
||||
try {
|
||||
const AsyncFunction = new Function(`return Object.getPrototypeOf(async function(){}).constructor`)();
|
||||
var evalFn = new AsyncFunction('moment', '_', 'components', 'queries', 'globals', 'axios', code);
|
||||
var evalFn = new AsyncFunction('moment', '_', 'components', 'queries', 'globals', 'axios', 'variables', code);
|
||||
result = {
|
||||
status: 'ok',
|
||||
data: await evalFn(moment, _, currentState.components, currentState.queries, currentState.globals, axios),
|
||||
data: await evalFn(
|
||||
moment,
|
||||
_,
|
||||
currentState.components,
|
||||
currentState.queries,
|
||||
currentState.globals,
|
||||
axios,
|
||||
currentState.variables
|
||||
),
|
||||
};
|
||||
} catch (err) {
|
||||
console.log('JS execution failed: ', err);
|
||||
|
|
|
|||
Loading…
Reference in a new issue