(sorry for my English)
I have a collection of data in which the user adds a message. If _AfterInsert() is triggered, I need this code to pass the last added item to the frontend code of the page.
How it should work:
1.) Any user leaves a message in the data collection. (Already working)
2.) _AfterInsert() triggered and backend code requests the last item, i.e. last item in data collection. (Already working)
3.) After that, the backend code (_AfterInsert() hook) should send the item (in JSON format) to the frontend page code. (I do not know how to do it)
Is it possible to realize this?
Hey
Can you describe how the front end page works or should work? If the user adds something on the front end it seem like going over the bridge to get water. If you want to get the last inserted item in a front end page you should insert the record on the front end page because then you will get that record at once.
But if you just want the last item from the data collection and not in particular that users last item just add a Dataset to the page, set the limit to 1 and the sort order to _createdDate = Descending and you will always be served the last inserted record in that dataset.
If you want to get that item in code use the below
let lastItem = $w("#dataset1").getCurrentItem();
// lastItem will hold the data from the last inserted/created item
Hope it helps!
I need that when adding each new item, it is automatically called into the code. In other topics for this advised to use hooks. I know about getcurrentitem, but it only calls item once. I need it to call item every time a new item appears in the data collection. (I tried to set getcurrentitem in the interval, but it gave the error “too many requests”)
There is a similar problem here, and I want about the same solution. With one exception only, that the last item should be returned to the code when the hook _AfterInsert () is triggered.