Is it possible to use insertReference inside a hook?

I’m trying to insert a reference field to a collection using a hook - the data is coming from outside the website, so I can’t do it via the page’s code itself. I tried with insertReference, and I also tried by updating the relevant item property with the _id of the referenced item - nothing works.

Without knowing what your outside usage is for your external data, have you looked into the Wix option of using an external dataset within your site?

As it does mention in that last link above that you can work with single references in your external dataset, however you can’t use multiple item reference fields.

Working with reference fields
You cannot work with multiple item reference fields in external database collections. You can only use single references in external databases, with the following implementation rules:

  • The reference must point to an _id field.

  • The reference field must be of type string.

  • To allow references from other collections to the external collection the _id field needs to accept the hasSome filter.