Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More

Qlik Sense Enterprise Client Managed: Bulk Update theme on all apps with Engine API (enigma.js)

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

Qlik Sense Enterprise Client Managed: Bulk Update theme on all apps with Engine API (enigma.js)

Last Update:

Jul 28, 2023 4:10:49 AM

Updated By:

Sonja_Bauernfeind

Created date:

Jul 28, 2023 3:24:55 AM

This article is provided as a sample on how to use the Engine API (Enigma.js) to bulk update the theme used on apps in Qlik Sense Client Managed.

Workflow of the sample:

  1. Get the list of apps with getDocList()
  2. Loop through each app, open it, update the theme and save.

Requirements

  1. A set of certificates need to be exported in pem format without password from the QMC and placed in the same format as the nodejs project.
  2. Node.js must be installed (This example was built and tested in version v18.17.0, there might be slight differences depending on the version)
  3. If the nodejs project is not running on the same machine as the Qlik Sense server, then port 4747 needs to be open for incoming connections on the Qlik Sense server.
This customization is provided as is. Qlik Support cannot provide continued support of the solution. For assistance, reach out to our Professional Services or engage in our active Integrations forum.

 

Usage

Copy the following script in a file called "change-theme.js" (Change the value of EngineHost to your server name)

 

 

const WebSocket = require('ws');
const enigma = require('enigma.js');
const schema = require('enigma.js/schemas/12.170.2.json');
const fs = require('fs');
const path = require('path');

const engineHost = 'qlikserver1.domain.local';
const enginePort = 4747;
const appId = 'engineData'; 

const userDirectory = 'INTERNAL';
const userId = 'sa_api';

const certificatesPath = './';

const readCert = (filename) => fs.readFileSync(path.resolve(__dirname, certificatesPath, filename));

function openSession(){
    return enigma.create({
  schema,
  url: `wss://${engineHost}:${enginePort}/app/${appId}`,
  createSocket: (url) => new WebSocket(url, {
    ca: [readCert('root.pem')],
    key: readCert('client_key.pem'),
    cert: readCert('client.pem'),
    headers: {
      'X-Qlik-User': `UserDirectory=${encodeURIComponent(userDirectory)}; UserId=${encodeURIComponent(userId)}`,
    },
  }),
})
}

(async () => {
  try {
    const session = openSession();
    const qix = await session.open();

    const apps = await qix.getDocList();
    console.log(apps.qDocId);

    await session.close();

     for (var p in apps) {
         console.log(apps[p].qDocId);

       const session = openSession();

    const params0 = {"qInfo":{"qId":"AppPropsList","qType":"AppPropsList"},"qAppObjectListDef":{"qType":"appprops","qData":{"sheetTitleBgColor":"/sheetTitleBgColor","sheetTitleGradientColor":"/sheetTitleGradientColor","sheetTitleColor":"/sheetTitleColor","sheetLogoThumbnail":"/sheetLogoThumbnail","sheetLogoPosition":"/sheetLogoPosition","rtl":"/rtl","theme":"/theme","disableCellNavMenu":"/disableCellNavMenu","chartAnimations":"/chartAnimations"}}};

var themename =`\"${process.argv[2]}\"`;
    const params1 = {
        "qPatches": [
            {
                "qOp": "replace",
                "qPath": "/theme",
                "qValue": themename
            }
        ],
        "qSoftPatch": false
    };

    const qix = await session.open();
    var app = await qix.openDoc(apps[p].qDocId);
    const objsession = await app.createSessionObject(params0);
    const objLayout = await objsession.getLayout();

    const AppPropObject = await app.getObject(objLayout.qAppObjectList.qItems[0].qInfo.qId)

    console.log(objLayout.qAppObjectList.qItems[0].qInfo.qId);

    await AppPropObject.applyPatches(params1);
    const resultsession = await AppPropObject.getProperties();

    console.log(resultsession);

    await app.doSave();
    await session.close();
    }

    console.log('Session closed.');
  } catch (err) {
    console.log('Whoops! An error occurred.', err);
    process.exit(1);
  }
})();

 

 

 

Copy the file in a folder and type the following commands ("horizon" is the name of the theme to change to in this example)

 

 

npm install ws enigma.js fs path
node change-theme.js horizon

 

 

 

Labels (2)
Version history
Last update:
‎2023-07-28 04:10 AM
Updated by: