I observed sometimes a data hook will not properly execute. On average the data hook will work.
How the one data hook works is, a item is inserted into a data set. It triggers an update to the same data set, then an email is sent via sendgrid.
When there is an issue, the data is not updated and a trigger is not sent. When I see this, I delete the row from the table and run the operation again and I can’t repeat the issue.
This doesn’t seem to be a hook problem. The update() function is just that - update. It can only be performed on an item that is identified by an _id . If there is no _id , then the update() function has nothing to update since it doesn’t know which item to update.
I’m using the _ID value in the data hook (Channel_Invite_afterInsert) after insert to populate the Primary Key (invite_key) with a unique value, so I can reference it another table with a reference field.
I do this for a bunch of tables.
The Channel_Invite_afterInsert hook (as others were I use the same methodology) fails randomly.
@brett82 Am I supposed to be looking at the Invite page? How about login credentials that I can use to test? Anything else? Keep in mind that the only way I can help is if I have a way to properly test.
Fair enough. Let me think about this. I’ve built something fairly unique. I’m using the invite as a way of validating user emails. For the scenario we are testing, it’s hard to simulate in the test environment. BTW: Is it possible reference fields might be creating issues with update statements, since the references have to be joined with a primary key in another table?
@brett82 I’m not sure what’s going on. Is there a case where the record doesn’t yet exist? In that case update() won’t work, but save() would.
Take a look at update() and you’ll see that it only updates - that is, if a record with the _id already exists it will be updated. If it doesn’t exist, then nothing happens. As the description for update() states: Updates an item in a collection.
On the other hand, save() might be better suited to your purpose. As the description states: Thesavefunctioninsertsor updates the specified item, depending on whether it already exists in the collection.
I’ll try to do some more testing tomorrow. However, it seems like the statement is having issues because the insert is not completely finished before the update commences. I can’t prove it yet, but that’s my hypothesis. It might be because I have reference fields in the databases.
So far, I haven’t any issues when I’ve added a setTimeout to some of the update statements.
That is: broadcast_event_key and NOTBroadcast_event_key . You need to be very careful to use the exact Field Key as displayed in the Manage Field panel.
Hopefully that’s it.
Let me know as soon as you find out - the suspense is killing me.