The question won’t make a ton of sense if I write it first so I’ve written a detailed breakdown of the data architecture, before the actual question for the forum.
Database Setup
Table: Document
- DocumentType (DocumentType) [defines the document template]
- Link (text) [useful for callback url in pdf generation]
- SavedResponses (list of FormResponse) [dynamically populates custom fields inside the Document]
- Status (DocumentStatus) [completed/draft]
Table: DocumentType [consider this a template that defines the content of the document]
- Title
TemplateQuestion:
- DisplayOrder (number) [Determines the ordering of the questions in the form]
- DocumentType (DocumentType) [Links each TemplateQuestion to a specific template]
- QuestionTitle (text) [self-explanatory]
- TemplateResponses (List of TemplateResponses) [Each TemplateQuestions can have more than one response and the response format is variable. So imagine a question inside of a form that requires 2 response types, the first being a select from available options and the other being a populate the input. If you scroll further down this post there is a TemplateResponse table that maps to a specific TemplateQuestion, so when a TemplateQuestion is loaded on the Form a search for linked TemplateResponses would be workload inefficient hence the pre-population of the TemplateResponses in the database].
Table: TemplateResponse
- DisplayOrder (number) [Determines the ordering of the TemplateResponses on the UI, for example if a TemplateQuestion requires a select and a custom user input, display order will number the options for the select chronologically i.e. 1,2,3 and 4. This is appropriate as the TemplateResponses are inside of a repeating group who’s content changes as the user moves through each step in the form]
- DocumentType (DocumentType) [Not strictly necessary as each TemplateResponse is mapped to a TemplateQuestion (who’s DocumentType is already defined), but useful for database search.
- TemplateQuestion (TemplateQuestion) [We used an API workflows on a list to automate the TemplateResponse population for each TemplateQuestion, so this is an identifier]
- Placeholder (text) [As previously mentioned some of the ResponseTypes are of type input from user, so this serves to as clarification tool on the type of response expected]
- ReponseText (text) [text shown on the front-end for each option, when the ResponseType of the TemplateResponse is either select or multiselect (not populated for input)]
- ResponseType (OS - ResponseType) [Select/Multiselect/Input]
- ConditionalResponse (yes/no for now) [response that is conditionally visible dependent on user selection for a qualifying response]
Table: Form Response
- Document (Document)
- ResponseTextInput1 (text) [Captures TemplateQuestions first user response via input using autobinding]
- ResponseTextInput2 (text) [Captures TemplateQuestions second user response via input using autobinding assuming there are two TemplateResponses for the parent TemplateQuestion]
- ResponseSelect (text) [Used to capture response from a list of options, where only one selection is allowed]
- ResponseMultiSelect (text) [Used to capture response from a list of options, where more than one selection is allowed]
Step (number) [Each step in the form is associated with one TemplateQuestion and each TemplateQuestions has a list of possible responses, the Document has a fields SavedResponses, so this fields helps associate FormResponses with a particular TemplateQuestion
Current build
At the moment, there is a build in place that works:, but is repetitive hence there must be a better solution. It looks something like this:
- User open a popup that allows them to select the DocumentType/Template they want to create.
- DocumentType selected fetches the associated TemplateQuestions, and goes to the TemplateQuestion who’s display order is 1. An empty Form Response is created, its step being the current step of the form (stored in custom state).
- User responds to TemplateQuestion, and the TemplateResponse is added to the FormResponse, the field that the TemplateResponse is mapped to in the form response depends on the reponsetype, so either responsetextselect, responsemultiselect, responseinput1 or response input2
- Use clicks buttons continue which makes changes to the parent Document field: SavedResponses adding the FormResponse and setting its item#: the current TemplateQuestion display order. Simultaneously, a new empty FormResponse is created and the step is set to currentstep +1. When user reaches the last TemplateQuestion for that DocumentType, we allow the user to create a pdf that contains a block of text (the template for that documenttype) with the custom fields dynamically populated by the associated FormResponses.
While the current workflow functions correctly, it doesn’t scale well as the number of templates grows. What I’d like instead is for admins to define “variables” (e.g. placeholders in the document) and assign each one a single value or a list of values. Those variable definitions would automatically surface as questions in the form ,much like our existing TemplateQuestions so end users can choose or enter values. Finally, when the user finishes, the system would merge their responses back into the text blocks and generate the PDF.
Im open to suggestions for a different approach, and I’d liken this post to a brainstorming session as opposed to a solution seeking post, so please don’t hesitate to suggest an approach even if you not entirely sure it will work.