Homeowner's Insurance Application
Prerequisites: Getting the Project Filesβ
Before you begin, this tutorial requires you to download two key assets from our GitHub repository:
- The "Form Template" Rule Project: The foundational project for creating dynamic forms.
- The Front-End Renderer: The HTML and JavaScript files needed to display the forms.
Follow these two steps to get everything you need.
Step 1: Import the Rule Projects into Studioβ
We use a PowerShell script to automatically find and install all the sample rule projects, including the essential "Form Template," into your Corticon.js Studio.
-
Navigate to the
sample-projectsDirectory: -
Download the Import Script:
- In the file list, find and click on
Import-CorticonSamples.ps1. - On the script's page, click the Download raw file button (the icon with a downward arrow).
- Save the script to a convenient location, like your Desktop.
- In the file list, find and click on
-
Run the Script:
- Open a PowerShell window, navigate to where you saved the file, and run it:
.\Import-CorticonSamples.ps1 - This script will temporarily clone the
dynamic-formsrepository in the background, find all the samples, and install them into your Corticon.js Studio.
- Open a PowerShell window, navigate to where you saved the file, and run it:
-
Restart Corticon.js Studio:
- After the script finishes, restart the studio. Go to Help -> Samples to find the "Form Template" project.
Step 2: Get the Front-End Filesβ
The front-end rendering application is in the front-end-files directory. We will use the downgit tool to download just this specific folder.
-
Download the Directory:
- Click this direct link to download the
front-end-filesdirectory as a ZIP file: - Download
front-end-filesusing downgit - This will download a file named
front-end-files.zip.
- Click this direct link to download the
-
Unzip the Files:
- Create a main project folder on your computer for this work (e.g.,
C:\corticon-tutorial). - Unzip the
front-end-files.zipdirectly into that folder. Your folder structure should now look like this:C:\corticon-tutorial\
βββ front-end-files\
βββ clientSideComponent\
βββ decisionServices\
βββ trace\
βββ index.html
βββ ... (and other files)
- Create a main project folder on your computer for this work (e.g.,
-
Important Note for Later:
- As you proceed through the tutorials, you will generate new Decision Services from Corticon.js Studio. You must save these into the
decisionServicessubfolder. For example:C:\corticon-tutorial\front-end-files\decisionServices\. This ensures the front-end application can find and load them.
- As you proceed through the tutorials, you will generate new Decision Services from Corticon.js Studio. You must save these into the
Tutorial: Building the Homeowner's Insurance Applicationβ
In this tutorial, you will build a practical, multi-stage application form for a homeowner's insurance policy. This project is a perfect example of how dynamic forms can handle complex data collection and even perform calculations.
What You Will Learn:
- How to model a more complex vocabulary for an insurance application.
- How to build a linear, multi-page form.
- How to use rules to perform a premium calculation based on user input.
- How to display the results of a calculation on a final summary screen.
Step 1: Building the Vocabularyβ
First, we will define the data model for our insurance application.
-
In Corticon.js Studio, open the Form Template project you imported earlier.
-
In the Project Explorer, open the
Rule Vocabulary.ecorefile. -
Expand the 'Data' folder in the rule vocabulary. Double click on the entity 'renameToYourPathToData', and enter
Homeowners. -
Right click on the entity called 'Data' and click 'Add Association'.
-
Β For the source entity name, keep 'Data.Data' for the the target entity name, select 'Data.Homeowners', and click the 'One' button beneath it. Then, change 'Navigability' to 'Data.Data->Data.Homeowners'.
-
Now, add the following attributes to your new
Homeownersentity. This will store all the information about the applicant, their property, and the final quote.
| Attribute Name | Data Type |
|---|---|
fullName | String |
street | String |
city | String |
state | String |
zipCode | String |
propertyType | String |
yearBuilt | Integer |
construction | String |
roofType | String |
securitySystem | Boolean |
swimmingPool | Boolean |
fireSuppress | Boolean |
coverageAmount | Decimal |
deductible | Decimal |
premium | Decimal |
- Save your vocabulary file.
Step 2: Creating the Form Stagesβ
We will now create a series of rulesheets to guide the user through the application process.
Stage 0: Applicant Informationβ
This stage collects basic information about the person applying.
- Create a New > Rulesheet named
Stage0_Applicant.ers. - Set the Precondition to
UI.currentStageNumber = 0. - In the Actions section, add the following rules:
- Set Data Path:
UI.pathToData='Homeowners' - Create Container:
UI.containers=Container.newwith atitleof'Applicant Information'. - Add Text Inputs: Create four
UIControl.newoftype'Text' for the applicant's full name and address. Link them to the vocabulary using thefieldNameattribute for each (fullName,street,city, etc.). - Set Next Stage:
UI.nextStageNumber=1
- Set Data Path:
Stage 1: Property Informationβ
This stage gathers details about the home to be insured.
- Create a New > Rulesheet named
Stage1_Property.ers. - Set the Precondition to
UI.currentStageNumber = 1. - Add the following rules:
- Create Container:
UI.containers=Container.newwith atitleof'Property Information'. - Add Dropdowns: Create
UIControl.newoftype'MultipleChoices' forpropertyType,construction, androofType. For each one, addOption.newentities to provide choices (e.g., forpropertyType, add options for 'Single Family Home', 'Townhouse', 'Condo'). - Add Number Input: Create a
UIControl.newoftype'Number' foryearBuilt. - Add Checkboxes: Create three
UIControl.newoftype'SingleChoice' forsecuritySystem,swimmingPool, andfireSuppress. - Set Next Stage:
UI.nextStageNumber=2
- Create Container:
Stage 2: Coverage Informationβ
Here, the user selects their desired coverage levels.
- Create a New > Rulesheet named
Stage2_Coverage.ers. - Set the Precondition to
UI.currentStageNumber = 2. - Add the following rules:
- Create Container:
UI.containers=Container.newwith atitleof'Coverage Details'. - Add Number Inputs: Create two
UIControl.newoftype'Number'. One forcoverageAmountand one fordeductible. - Set Next Stage:
UI.nextStageNumber=3
- Create Container:
Stage 3: Calculate Quote (Non-Visual)β
This special stage performs the premium calculation in the background without showing anything to the user.
- Create a New > Rulesheet named
Stage3_Calculate.ers. - Set the Precondition to
UI.currentStageNumber = 3. - Add the following rules:
- Enable Background Processing:
UI.noUiToRenderContinue=true. - Base Premium Rule: In the Actions, set
Homeowners.premium=Homeowners.coverageAmount * 0.005. This sets a base premium. - Add Surcharge Rules: Create several Conditional Rules. For example:
- Condition:
Homeowners.swimmingPool = true - Action:
Homeowners.premium += 150 - Condition:
Homeowners.roofType = 'Wood Shake' - Action:
Homeowners.premium += 200
- Condition:
- Add Discount Rules: Create conditional rules for discounts:
- Condition:
Homeowners.securitySystem = true - Action:
Homeowners.premium -= 75
- Condition:
- Set Next Stage:
UI.nextStageNumber=4
- Enable Background Processing:
Stage 4: Display Quoteβ
This final stage displays the calculated premium to the user.
- Create a New > Rulesheet named
Stage4_Quote.ers. - Set the Precondition to
UI.currentStageNumber = 4. - Add the following rules:
- Create Container:
UI.containers=Container.newwith atitleof'Your Quote'. - Display Premium: Create a
UIControl.newoftype'ReadOnlyText'. Set itsvalueto the string'Your calculated annual premium is: $' + Homeowners.premium. - End the Form:
UI.done=true.
- Create Container:
Step 3: Assembling the Ruleflowβ
Just like our first tutorial, we will let the rules handle the flow.
- Create a New > Ruleflow named
Homeowners.erf. - Drag all five of your rulesheets (
Stage0throughStage4) onto the canvas. - Do not connect them. The
currentStageNumberprecondition on each sheet will control the execution order.
Step 4: Testing Your Logicβ
Use the Ruletester to verify your calculations.
- Test Case 1 (Premium Calculation):
- Input: Create a
UIobject withcurrentStageNumber = 3. Create aHomeownersobject with values likecoverageAmount = 300000,swimmingPool = true, andsecuritySystem = true. - Expected Output: The
UIobject should havenextStageNumber = 4. TheHomeowners.premiumshould be calculated correctly (e.g., (300000 * 0.005) + 150 - 75 = 1575).
- Input: Create a
Conclusionβ
Great job! You have now built a complete insurance application form that not only collects data across multiple stages but also uses conditional logic to perform calculations and display a result. You are well on your way to mastering dynamic form creation.