From da73693ea0e63d71d380d9336c7ca0ec105a43e5 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 21 Jun 2026 08:50:43 +0200 Subject: [PATCH] fix(qlik): resolve 4 new measures by title, not QRS GUID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new measures returned 0 because their qLibraryId was set to the QRS object GUID, but the engine references master measures by qInfo.qId (short codes like JhqJ) — an unknown GUID is silently ignored and yields null. Resolve CA par Magasin / Couverture / Marge % / Rupture % by title via the in-page MeasureList (whitespace+case normalized), falling back to the configured id, and log the resolved ids. Co-Authored-By: Claude Opus 4.8 --- src/lib/qlik-playwright.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib/qlik-playwright.ts b/src/lib/qlik-playwright.ts index e2155d0..13d8405 100644 --- a/src/lib/qlik-playwright.ts +++ b/src/lib/qlik-playwright.ts @@ -110,9 +110,22 @@ export async function fetchNetworkMetricsPlaywright( const sel = await rpc("SelectValues", { qFieldValues: codes.map((c) => ({ qText: c })), qToggleMode: false, qSoftLock: true }, fh); console.log("SelectValues " + codes.length + " codes → " + JSON.stringify(sel.qReturn)); } + // Résoudre les master measures par TITRE (le qLibraryId fiable = qInfo.qId, ≠ GUID QRS). + const norm = (s: string) => s.replace(/\s+/g, " ").trim().toLowerCase(); + const ml = await rpc("CreateSessionObject", { qProp: { qInfo: { qType: "MeasureList" }, qMeasureListDef: { qType: "measure", qData: { title: "/qMetaDef/title" } } } }, doc); + const mll = await rpc("GetLayout", {}, (ml.qReturn as { qHandle: number }).qHandle); + const items = (((mll.qLayout as { qMeasureList?: { qItems?: Array<{ qInfo: { qId: string }; qMeta?: { title?: string }; qData?: { title?: string } }> } }).qMeasureList?.qItems) ?? []); + const byTitle = new Map(); + for (const it of items) { const t = it.qMeta?.title ?? it.qData?.title ?? ""; if (t) byTitle.set(norm(t), it.qInfo.qId); } + const pickMeasure = (title: string, fallback: string) => byTitle.get(norm(title)) ?? fallback; + const rCamag = pickMeasure("CA par Magasin N", mcamag); + const rCouv = pickMeasure("Couverture de stock Quantité N", mcouv); + const rMarge = pickMeasure("Marge % N", mmarge); + const rRupt = pickMeasure("Stock Rupture % N", mrupt); + console.log("measures résolues par titre: " + JSON.stringify({ rCamag, rCouv, rMarge, rRupt }) + " (sur " + items.length + " mesures)"); const obj = await rpc("CreateSessionObject", { qProp: { qInfo: { qType: "cf-net" }, qHyperCubeDef: { qDimensions: [{ qLibraryId: dim }], - qMeasures: [{ qLibraryId: mca }, { qLibraryId: mqte }, { qLibraryId: mnb }, { qLibraryId: mcamag }, { qLibraryId: mcouv }, { qLibraryId: mmarge }, { qLibraryId: mrupt }], + qMeasures: [{ qLibraryId: mca }, { qLibraryId: mqte }, { qLibraryId: mnb }, { qLibraryId: rCamag }, { qLibraryId: rCouv }, { qLibraryId: rMarge }, { qLibraryId: rRupt }], qInitialDataFetch: [], } } }, doc); const oh = (obj.qReturn as { qHandle: number }).qHandle;