Hi,
I’ve created a plugin to sync resource input to an external database. In order to avoid duplicate entries I receive an ID from the API which I store in a TV so I can use this as a reference for future syncs.
According to the docs this is best done in the ‘OnDocFormSave’ event (TVs are best Modified Here If you need to modify TV values, it’s best to modify them here and not during OnBeforeDocFormSave.).
All of this is working great, but when there’s an error in the sync (missing fields, wrong input,…) I need a way to notify the user that there are things that went wrong which I can only do ‘OnBeforeDocFormSave’ (Unlike OnBeforeDocFormSave, this event does not support the $modx->event->output() method.).
I’m now sending an e-mail to the user with the feedback, but this is far from ideal.
Any ideas on how to improve this? Preferably with a ‘standard’ notification/error.
Thanks, Steffan
On which event does this synchronization happen? On ‘OnDocFormSave’?
Would you prefer to call the API on the event ‘OnBeforeDocFormSave’?
You could for example “pass” the return value from the API from the ‘OnBeforeDocFormSave’ event to the ‘OnDocFormSave’ event by using the superglobal $_POST
. Or you could store the reference directly in the resource (e.g. in the field “properties”) without using a TV at all.
1 Like
Ah, didn’t think of that. Both good suggestions, thanks for setting me on the right track!
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.