Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

"SubscriptionComplete" event?

Avatar

Level 2

I've got just one short question: is there some kind of event to check whether the subscription to a SharedProperty or SharedCollection is complete?

Kind regards,

Hans

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Hi,

Once you call subscribe, you need to wait till the synchronization is complete, else it will say you aren't subscribed yet and throw errors. Add the handler to synchronizationChange event of SharedCollection, and when you come into the handler and it's synchronized, you can add any local values to it.

First the SharedCollection has to be synchronized with server before adding value, which kicks out once you call sharedCollection.subscribe(). There are many examples displaying this.

Hope this helps.

Thanks

Hironmay Basu

View solution in original post

4 Replies

Avatar

Former Community Member

Hi,

What do you mean by subscription to SharedProperty or SharedCollection. If you haven't subscribed to any of those, you won't receive any item or events on them and they won't be synchronized. You can use isSynchronized to check that.

Thanks

Hironmay Basu

Avatar

Level 2

Hi,

I want to put some initial values in a SharedCollection. I thought doing this by letting the first connected user fill a local array with the values, and then copying them to the SharedCollection. When I put this function straight after the initialization and subscription to the SharedCollection, I get null exceptions or errors saying that I am not subscribed to the SharedCollection (probably because the subscription is asynchronous). Therefor I thought of triggering the function that copies the local values to the SharedCollection by some kind of 'SubscriptionComplete' event or something, saying that the SharedCollection is connected.

Probably I can use the isSynchronized property to accomplish such a thing.

Thanks,

Hans

Avatar

Former Community Member

Hi Hans,

synchronizationChange should get dispatched once the property is done subscribing.

hope that helps

nigel

Avatar

Correct answer by
Former Community Member

Hi,

Once you call subscribe, you need to wait till the synchronization is complete, else it will say you aren't subscribed yet and throw errors. Add the handler to synchronizationChange event of SharedCollection, and when you come into the handler and it's synchronized, you can add any local values to it.

First the SharedCollection has to be synchronized with server before adding value, which kicks out once you call sharedCollection.subscribe(). There are many examples displaying this.

Hope this helps.

Thanks

Hironmay Basu

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----