Hi,
I have a DM which models some specific metadata for an email file (.msg): an attachment for the file and fields like Subject, From, To, CC, etc. These fields should be filled with the data in the file.
At the moment, I read that data before creating the document by hooking at DocumentBeforeCreateEvent. This means, the user sees the data after saving and reopening the corresponding document.
Now, I would like to improve the end-user experience and show the data already after the server has checked the attachment, i.e. before the user clicks on “submit”/“save”.
Has anyone already implemented a solution for a similar requirement?
Hello @gildardo-cached-canyon,
This functionality must be implemented on the client side because the creation of an attachment is decoupled from its assignment to a document. The primary concept is that either the client or the form engine (the appropriate choice for this responsibility is yet to be determined) should provide information about the current state of the document as well as the metadata associated with the attachment. Attachments are initially created independently and are not linked to any document upon upload. Therefore, after an attachment is uploaded, there is no associated document. The association between the attachment and the document can only occur once the document has been submitted. At that point, both entities can be linked and utilized within the extension point.
Thanks @tomas-thin-gale for the reply. That is what I thought after seeing that all the attachment-events don’t have any reference to the document, but I was not 100% sure.
I have just changed the cathegory of this thread to ‘client’.
Hi,
In theory, you could intercept the action that sets the attachment and extract the information there (e.g. with a saga).
A saga has full state access, so you could:
- look into the attachment that was just uploaded and extract arbitrary data from it
- manipulate the document by setting arbitrary values (since you know where the fields are)
However, I would strongly recommend against this approach, since you would have to validate this data on the server side anyway → meaning the logic on the client side (that “knows” how to extract data from a file object) would have to be implemented on the server side as well (to ensure that the client side did not inject any malicious data).
Therefore, I would suggest trying to just do this logic on the server (ideally with something like an event hook for “upload attachment request received” or similar) and then send the data back to the client.