Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE

How to scramble data with Qlik Sense Desktop and Node.js

No ratings
cancel
Showing results for 
Search instead for 
Did you mean: 
Damien_Villaret
Support
Support

How to scramble data with Qlik Sense Desktop and Node.js

Last Update:

Oct 27, 2020 6:07:56 AM

Updated By:

Sonja_Bauernfeind

Created date:

May 16, 2019 11:12:38 AM

This explains how to use Qlik Sense Desktop and the Engine API called through Node.js (enigma.js module) in order to scramble data for an app.

Environments:
  • Qlik Sense Desktop June 2017 and higher
  • Node.js (module: ws, enigma.js)

 

Resolution:


On the machine where you have Qlik Sense Desktop installed, install node.js, create a new folder for your node project and install the following modules:

npm install ws enigma.js

Copy the following code in a file named scramble.js and save it in the same folder:

const WebSocket = require('ws');
const enigma = require('enigma.js');
const schema = require('enigma.js/schemas/12.170.2.json');
 
const qParam = {
  "qInfo": {
    "qId": "",
    "qType": "FieldList"
  },
  "qFieldListDef": {
    "qShowSystem": true,
    "qShowHidden": true,
    "qShowSemantic": true,
    "qShowSrcTables": true
  }
};
 
(async () => {
  try {
    console.log('Creating app on engine.');
    const session = enigma.create({
      schema,
      url: 'ws://localhost:9076/app/',
      createSocket: url => new WebSocket(url),
    });
    const qix = await session.open();
    var app = await qix.openDoc(process.argv[2]);
    const objsession = await app.createSessionObject(qParam);
             
    const fields = await objsession.getLayout();
    const results = fields.qFieldList.qItems;
 
    for (var p in results) {
        var myfield = JSON.stringify(results[p]['qName']).replace(/"/gi,'');
                            if (myfield.includes("$")==false){
                                          console.log(myfield);
                                          await app.scramble(myfield);
                            }
      }
 
    await app.doSave();
 
    await session.close();
    console.log('Session closed.');
  } catch (err) {
    console.log('Whoops! An error occurred.', err);
    process.exit(1);
  }
})();

Launch Qlik Sense desktop and log in, once you reach your list of apps, open a command prompt, move to the folder where scramble.js has been copied and execute the following:

node scramble.js "Consumer Sales"

Replace "Consumer Sales" by the name of the app you want to scramble.
If this is successful, the list of fields getting scrambled will be displayed, and a message "Session Closed" will be printed when the process is over.

Now, if you close Qlik Sense Desktop, reopen it and open your app again, you can verify that the fields in the app have been scrambled correctly.

Labels (1)
Contributors
Version history
Last update:
‎2020-10-27 06:07 AM
Updated by: