objectId is undefined in triggers

I’m using trigger on a mongodb table, when I try to get the objectId I always get undefined

I’ve tried multiple ways of getting it

request.object.get('object_id'); 
request.object.get('objectId');
request.object.get('id');

all result in undefined

My workaround is following

	let stuff = JSON.stringify(request);
	let newObj = JSON.parse(stuff);
	newObj.object.id //this works

Maybe you can check it out or maybe I’m calling it wrongly

you could try to use logger.info(JSON.stringify(request.object)) to see how you can access it

you can also try a syntax like request.object[‘id’], even if it should to the same thing as .get(‘id’)

Thats what I did and found that workaround, here is the json

{
    "triggerName": "afterSave",
    "object": {
        "block_timestamp": {
            "__type": "Date",
            "iso": "2021-11-26T16:22:29.000Z"
        },
        "transaction_hash": "0x33fc4e475c56999a1bfc8f680a68ad900f697fd2271847cb16237d4ad98af6cb",
        "log_index": 42,
        "amount": "9995000",
        "tokenAddress": "0xe31e99a168066b530bf8301ab9353c8cd57a3656",
        "address": "0x5c768cfd37ee08da4eaeb19cd96522822741d8e8",
        "block_hash": "0xa51bad8bdda70c5001e8c60193471d3d5910ccacef9b9e9010df636342e91caa",
        "block_number": 9710694,
        "transaction_index": 6,
        "createdAt": "2021-11-26T16:22:31.856Z",
        "updatedAt": "2021-11-26T16:22:31.856Z",
        "objectId": "38WNhmGB8wuN84WCTqxgUZ4V"
    },
    "master": true,
    "log": {
        "options": {
            "jsonLogs": false,
            "logsFolder": "./logs",
            "verbose": false
        },
        "appId": "WrszROWRp7oShP39MWHMLl4mMA6n2QMN8LDRD6gi"
    },
    "context": {},
    "installationId": "cloud"
}

and was trying to get objectId:“38WNhmGB8wuN84WCTqxgUZ4V”

I can confirm that request.object[‘id’] does work, while request.object.get(‘id’) does not work

I can confirm that request.object[‘id’] does work, while request.object.get(‘id’) does not work

Why this is not addressed???

I’ve wasted 3 hrs of my life until I found this comment…

Keep nice tone in the forum @Mugen we are here to help for free and you have to respect the mods - we don’t tolerate this tone and have no interest in having it on the forum if we see you go wild again :slight_smile:

Say “thanks” when you get help and appreciate the help - don’t use “!!!”, “…” no one wants to help someone using such disrespect

Thanks for understanding and happy BUIDL!
————————

Back to the issue in question

I think request.object.id should work straight off the bat

Thanks for pointing out about the behaviour but sorry I don’t see how I was rude about pointing out that this is not addressed? i bet I’m not the only one who stumbled upon this problem and the issue is that it doesn’t seem to be documented. This just show inconsistency in the API coz every other element from objects is able to be retrieved via .get but id is not. And there is nothing about it in docs as far as I went through them.

1 Like

Dont get me wrong. I didnt mean to be in any way rude. So if this comments feels like that I apologise. :slight_smile:

1 Like

You can contribute to current documentation on GitHub if you want to help.

yea we need to improve docs, no worries :slight_smile:

but so to confirm - request.object.id works straight off the bat?

1 Like

but so to confirm - request.object.id works straight off the bat?

Yes