From 5da8640beaf25dcb985c3fae496bf02e113c046b Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 6 Aug 2024 14:26:31 +0200 Subject: [PATCH] allow metadata is still not in context after apply expression over a metadata2 --- lib/services/ngsi/entities-NGSI-v2.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/services/ngsi/entities-NGSI-v2.js b/lib/services/ngsi/entities-NGSI-v2.js index 9feabac61..ec83729b5 100644 --- a/lib/services/ngsi/entities-NGSI-v2.js +++ b/lib/services/ngsi/entities-NGSI-v2.js @@ -537,9 +537,14 @@ function sendUpdateValueNgsi2(entityName, originMeasures, originTypeInformation, currentAttr.metadata[metaKey] = newAttrMeta; //RE-Populate de JEXLcontext - if (jexlctxt.metadata && jexlctxt.metadata[currentAttr.name]) { - jexlctxt.metadata[currentAttr.name][currentAttr.metadata[metaKey]] = metaValueExpression; + // It is possible metadata is still not in ctxt + if (!jexlctxt.metadata) { + jexlctxt.metadata = {}; } + if (!jexlctxt.metadata[currentAttr.name]) { + jexlctxt.metadata[currentAttr.name] = {}; + } + jexlctxt.metadata[currentAttr.name][currentAttr.metadata[metaKey]] = metaValueExpression; } } }