Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Jul 28, 2023 4:10:49 AM
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:
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.
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