How to access my custom data in POJO object in Javascript enrichment

Hi,

we are collecting data in our custom schema. This schema is quite simple:

{
    "$schema": "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
    "self": {
      "vendor": "cz.activate",
      "name": "equa-form-validation",
      "format": "jsonschema",
      "version": "1-0-0"
    },
    "type": "object",
    "additionalProperties": true,
    "properties": {
        "processId": {
            "type": "string"
        },
        "pageId": {
            "type": "string"
        },
        "fieldActionType": {
            "type": "string"
        },
        "fieldAction": {
            "type": "string"
        },
        "formId": {
            "type": "string"
        },
        "fieldId": {
            "type": "string"
        },
        "fieldActualValue": {
            "type": "string"
        },
        "activeElement": {
            "type": "string"
        }
    }
}

Data are stored in BigQuery as columns like:
unstruct_event_cz_activate_equa_form_validation_1_0_0.field_actual_value

I would like to access those data in an custom javascript enrichment. But it doesn’t work for me.
I can access all field from canonical datamodel using PoJo getters:

var query=event.getPage_urlquery()

It works fine. But I can’t fid out the correct getter function for accessing data from my custom schema.
Thans for any help.

Hi @Jiri_Stepan, welcome to the Snowplow community!

If I understand correctly you’re sending events as custom events (e=ue). In that case, the self-describing JSONs that you’re sending are available in event.getUnstruct_event(). Please note that they are stored as String, so you need to parse them as JSON first (JSON.parse()) and then you can access directly the fields that you want (e.g. json.fieldActualValue).

Thank you.very much! It’s exactly what I was looking for.

Just for future record. The JSON result of getUnstruct_event() is a bit more complicated. So you have to use json.data.data.fieldActualValue.

Example:

{

    "schema": "iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0",

    "data": {

        "schema": "iglu:cz.activate/equa-form-validation/jsonschema/1-0-0",

        "data": {

            "processId": "testProces5",

            "pageId": "/cashloan/testPageId",

            "formId": "form1",

            "fieldId": "name",

            "fieldActionType": "FieldInteraction",

            "fieldAction": "KeyDown",

            "fieldActualValue": "314",

            "activeElement": "test-input"

        }

    }

}