-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathparameter-passing.js
67 lines (62 loc) · 1.68 KB
/
parameter-passing.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const createSession = require('../../session');
// inline script with a simple table
const script = `
exampletable:
load * Inline [
dim, val
foo, 23
bar, 42
c, 54
d, 21
];
`;
const session = createSession();
/**
* Write the tabelContent to console.
* @param {*} tabelContent
*/
function print(tableContent) {
for (let i = 0; i < tableContent.length; i += 1) {
console.log(`dim: ${tableContent[i].qValue[0].qText} val: ${tableContent[i].qValue[1].qText}`);
}
}
// local variable to store the generated sessionapp
let sessionApp;
session.open()
.then((global) => global.getActiveDoc())
.then((app) => {
sessionApp = app;
return app.setScript(script);
})
.then(() => sessionApp.doReload())
.then(() => Promise.all([
/**
* The first example shows how to pass the parameter by position. By this way you pass
* parameters by position in the order defined by the QIX method.
*/
sessionApp.getTableData(0, 4, false, 'exampletable')
.then((tableContent) => {
console.log('Position based');
print(tableContent);
}),
/**
* The second example shows how to pass the parameter by name. By this way you can
* pass the parameters wrapped in an object, and define the parameters with the specific
* name. The order is not important.
*/
sessionApp.getTableData({
qTableName: 'exampletable',
qSyntheticMode: false,
qOffset: 0,
qRows: 4,
})
.then((tableContent) => {
console.log('Name based');
print(tableContent);
}),
]))
.then(() => session.close())
.catch((error) => {
console.log('Error during communication with engine', error);
process.exit(1);
});