Running a trigger when a child is linked to an asset


(Phil Mcphee) #1

I'm trying to build a forum from scratch in Matrix, and one of the things I want to do is be able to sort "threads" (I'm using news item assets) by when they were most recently commented on (i.e. a new comment asset is created as a child) in an asset listing.


The only approach I can think of that will work is to have date metadata on the news asset which gets updated via a trigger when a new comment is added. The problem I've run into is that I can't find an event that lets me get at the parent news item. I would have thought that "link created" would work, but that only seems to fire when I "new link" in the asset map, rather than on the initial asset creation. I can obviously get "asset created" to fire when the comment is added, but there doesn't seem to be an action that lets me manipulate the parent news item.



Any ideas?


(Ashish Karelia) #2

Hi,
what you are trying to achieve, according to me, won't be possible through trigger. Or atleast through simple triggers. It at all it is achieveable then it will get very complicated.

Have you thought of using JS API in these bits? JS API will not only be able to get you the parent of the comment (getParents()) but will also help you edit the link sort order (updateLink()) to bring up the asset position under the main node of the news items.



Ash



EDIT: Actually you might not need the updateLink() mentioned. As you are sorting on the asset listign using the metadata field value.


(Nic Hubbard) #3

Had an excellent idea but it seems to not work after testing it… :frowning:


I agree with Ashish that using the JS API is going to give you the most flexibility.


(Phil Mcphee) #4

Thanks guys - super-quick answers! I think I'll use JS API like you suggest and set the metadata of the parent asset when the comment is created.