I've written some code for custom entities that dynamically presents questions that the user must answer. The code creates answer records, that are then associated with it's parent record.
My issue is that I'd like users to be able to complete the answers BEFORE having to save the record for which they are answering the questions. The problem is that in order to associate the answers records to a parent record, the parent record must have a guid value, and this is only created once the record is saved.
My idea is that I can store the answer record guid values in a global array, and OnSave of the parent record, go update the answer records accordingly to link them to the parent. BUT when I save the record, my global gets wiped clean.
Is there any way to preserve the values stored in that global array? Or does anyone have a more clever way to route around this issue? Thanks very much for any help.
Keeping in mind that you're using a HTML Web Resource and you will have access to the Global Context, I can think in these alternatives:
Force the user to manually save the record: I know that you want to avoid this option, but this behaviour would be similar to the one that the grids have (they show a message which says "To enable this content, save the record"). You can accomplish this using the Form Type.
Save the temporary data in a hidden field: instead of using a global array to save the answers you can use a hidden field in your parent entity so the data will be preserved. You will be able to create the related entities when the form loads again (to reuse the code that you have in place now) or use a plugin (Post Create of your parent entity).