GetMetadataPropertyValue overrides field value

Pedro Heleno Isolani 6 Reputation points

Microsoft Learn recommend using the unique EventId property with GetMetadataPropertyValue to generate a unique identifier for an event (i.e., a UUID). However, when the event message content has a field called eventid, this is overwritten when calling the GetMetadataPropertyValue([iothubingest], 'EventId').

Messages are created with javascript and the data is generated as follows:

var eventid = randomNumber(1, 15); var data = JSON.stringify({ description: "test " + eventid, eventid: eventid, }); return data;

An example message sent and its format is presented below:

{"description":"test 4","eventid":4}

Below are the screenshots using and not using the function. The output of event_id when using the function gets overwritten by its value.



If there is a way to read GetMetadataPropertyValue([iothubingest], 'EventId') without replacing eventid from the message itself, please let me know.

Azure IoT
Azure IoT
A category of Azure services for internet of things devices.
362 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Joe Zhang 91 Reputation points Microsoft Employee

    This is a design flaw that always existed in the system but was not uncovered until some recent past. The issue is that compiler identifies which metadata fields are asked to be included based on the query (like using GetMetadataPropertyValue) and passes this information to the input, where then the metadata fields are extracted and added to the payload.
    On one hand it avoids polluting payload with all the metadata available, but on the other hand it creates a problem when system metadata field name clash with already present payload field name. In which case metadata value being injected in the payload overrides the original value.
    It was initially observed with "PayloadId" and then also with "EventId", and generally when chaining multiple ASA jobs via EH.
    The only way to avoid this at present time is to rename original payload field before it gets to the ASA input.

    1 person found this answer helpful.