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"

        }

    }

}

Hey!

This was very helpful to me too, thank you!

I’m wondering if there’s a place where the POJO getters are documented? I couldn’t find any.
I can only assume their format and case but I have no way to confirm them other than testing them.

For example, if I want to access se_property, I assume the getter would be getSe_property() but this assumption is only empirical.

If there’s no doc on it, could anyone confirm me the getters format please?
Thanks a lot!

Hey @Timmycarbone
A full list of the available information can be found by looking at the class definition of an Event.

You can take any of those properties and add get and then camelCase it. So in your example getSe_property() should be correct.

The Custom JavaScript Enrichment is documented here: Custom JavaScript enrichment - Snowplow Docs

2 Likes