How To Use Instances

Learn how to submit values for parameters that have multiple instances.

As discussed in our risk and coverage parameter doc, some risk and coverage parameters can have multiple values. In the Dynamic Application, we communicate that a parameter can have multiple values using the property creates_array: true, and each instance of that parameter is given a unique instance to distinguish between them.

The Purpose of Instances

Most of the questions on an application are unique, in that they can only have 1 value. As an obvious example, an applicant can only have 1 insured name on an application. However, some risks and coverages can have multiple values, to support cases such as an applicant with multiple locations, multiple class codes, or multiple domain names.

Let’s look at an example where an applicant has multiple locations and multiple class codes.

  • The applicant has a manufacturing location in Los Angeles
  • The applicant has a sales and marketing center in San Francisco.

This application would need multiple instances of risk parameter rsk_yor8_location for location, and multiple instances of risk parameter rsk_km7k_gl_class_code_by_location for class code which is a child of location. In this example, the application would include 2 instances of location, and 3 instances of class code (1 for manufacturing in Los Angeles, and 2 for sales and marketing in San Francisco).

By default, the Dynamic Application only provides 1 instance of each parameter. You can generate additional instances by following the steps below.

Since there will be multiple instances of the same risk parameter, Herald assigns a unique instance to each case of the risk parameter to distinguish between them. This makes it easy to keep track of individual instances and map values to the correct instance, like this:

Instances in Dynamic Applications

Every risk or coverage parameter that supports multiple values will have 2 distinct properties associated with it: creates_array: true to communicate that the parameter can have multiple values, and the unique instance instance of that parameter.

In the example above, we have:

  • 2 instances of location, for Los Angeles and San Francisco
  • 1 instance of class code below the Los Angeles location, for manufacturing
  • 2 instances of class code below the San Francisco location, for sales and marketing.

These parameters would be returned like this:

Copied
{
    "risk_parameter_id": "rsk_yor8_location",
    "instance": "location_1",
    "value": {
        "line1": "3325 Wilshire Blvd",
        "city": "Los Angeles",
        "state": "CA",
        "postal_code": "90010",
        "country_code": "USA"
    },
    "child_risk_values": [
        {
            "risk_parameter_id": "rsk_km7k_gl_class_code_by_location",
            "instance": "location_1.gl_class_code_by_location_1",
            "value": "53731",
        }
    ]
},
{
    "risk_parameter_id": "rsk_yor8_location",
    "instance": "location_2",
    "value": {
        "line1": "308 Eddy St",
        "city": "San Francisco",
        "state": "CA",
        "postal_code": "94102",
        "country_code": "USA"
    },
    "child_risk_values": [
        {
            "risk_parameter_id": "rsk_km7k_gl_class_code_by_location",
            "instance": "location_2.gl_class_code_by_location_1",
            "value": "16900",
        },
        {
            "risk_parameter_id": "rsk_km7k_gl_class_code_by_location",
            "instance": "location_2.gl_class_code_by_location_2",
            "value": "99160",
        }
    ]
},

Creating New Instances

By default, the Dynamic Application only provides 1 instance of each parameter. When building a front-end application, Herald recommends that you give applicants the ability to add additional instances, to support applicants with multiple locations or multiple domains. Our guide to building a front-end provides some guidance on rendering this experience, but for now we’ll cover how to create additional instances using Dynamic Application.

You can create an additional instance by including an additional parameter via PUT /applications. Let’s walk through the example from above. When you first create the application, the response only includes 1 instance of each parameter.

To add a second instance, you should call a function to submit an additional instance of the parameter. That function should have 3 inputs:

  • Parameter Type: Either a Risk Parameter (which would use risk_parameter_id) or a Coverage Parameter (which would use coverage_parameter_id).
  • The Parameter ID: The actual ID for the parameter, such as rsk_yor8_location.
  • The Parent Array: The parameter could be nested within the risk_values array or coverage_values array, or it could be nested below a parent parameter.

Example function:

Copied
addNewInstance(parameter, parentArray, paramType){
    parentArray.push({paramType === 'risk parameter' ? 'rsk_parameter_id' : 'cvg_parameter_id' : parameter.id });
    this.shouldShowAddButton = false;
}

Let’s walk through the example from earlier where an applicant has 2 locations. When you first create the application, the response will only include 1 instance of location:

Copied
"risk_values": [
    {
        "risk_parameter_id": "rsk_yor8_location",
        "instance": "location_1",
        "value": null,
        "creates_array": true,
        "required_for": ["quote"],
    },
    ...
]

Note that the parameter is required_for: [”quote”]. This is because at least 1 value is required by the carrier.

The parameter for location is a Risk Parameter with the ID rsk_yor8_location, nested within the risk_values array. To create the additional instance of location, you would make a PUT request with the following:

Copied
"risk_values": [
    {
        "risk_parameter_id": "rsk_yor8_location",
        "instance": "location_1",
        "value": null,
        "creates_array": true,
        "required_for": ["quote"]
    },
    {
        "risk_parameter_id": "rsk_yor8_location",
    }
]

The Application response will now include 2 instances of location, and automatically generate the new instance. Note that the additional instance is required_for: [ ] because the additional location is optional.

Copied
"risk_values": [
    {
        "risk_parameter_id": "rsk_yor8_location",
        "instance": "location_1",
        "value": null,
        "creates_array": true,
        "required_for": ["quote"],
    },
    {
        "risk_parameter_id": "rsk_yor8_location",
        "instance": "location_2",
        "value": null,
        "creates_array": true,
        "required_for": [ ],
    },
]

On a front-end, you would power this by rendering an Add + button below every parameter that has creates_array: true. When the button is clicked, you would call the function to generate a new instance of the parameter, make a PUT, and receive the additional instance. This can be done any incremental amount of time. Read our guide to building a front-end to learn more.

If you already know an applicant has multiple locations, or multiple values for any parameter, you don’t have to add them one at a time. You can include any amount of instances and values when updating your application.

Deleting Instances

You can delete instances using a similar method to adding instances. On a front-end, you can generate a Remove - button below each instance when multiple are present. Since at least 1 value is required, this feature must be restricted when only 1 instance is present.

When adding an additional instance, you add an additional instance of a parameter to the /applications request and make a PUT. To remove an instance, you remove the specific instance from the /applications request and make a PUT.

Following the example from above, let’s say the applicant now wants to remove the second location which has the instance location_2. To remove this location, you would remove that entire parameter from the application body, and make a PUT.

Copied
"risk_values": [
    {
        "risk_parameter_id": "rsk_yor8_location",
        "instance": "location_1",
        "value": null,
        "creates_array": true,
        "required_for": ["quote"],
    },
    {
        "risk_parameter_id": "rsk_yor8_location",
        "instance": "location_2",
        "value": null,
        "creates_array": true,
        "required_for": [ ],
    },
]

The following application response will now only include the first location, which has the instance location_1. It’s important to use instance to make sure you are removing the correct values from an application.

Using Instance to Map Values

Using instance is very important when removing a specific value, and submitting a value below a parent parameter. In the example we’ve been using, an applicant has multiple locations with unique class codes for each building.

  • The applicant has a manufacturing location in Los Angeles
  • The applicant has a sales and marketing center in San Francisco.

In this example, we need to make sure we submit the class code value for manufacturing below the location for Los Angeles, and the class codes for sales and marketing below the location for San Francisco.

Since class codes and locations have a parent/child relationship, the value for each class code must be nested below the child_risk_values of the correct parent instance. In this case, we start with 2 locations:

Copied
{
    "risk_parameter_id": "rsk_yor8_location",
    "instance": "location_1",
    "value": {
        "line1": "3325 Wilshire Blvd",
        "city": "Los Angeles",
        "state": "CA",
        "postal_code": "90010",
        "country_code": "USA"
    },
    "child_risk_values": [
        {
            "risk_parameter_id": "rsk_km7k_gl_class_code_by_location",
            "instance": "location_1.gl_class_code_by_location_1",
            "value": null,
        }
    ]
},
{
    "risk_parameter_id": "rsk_yor8_location",
    "instance": "location_2",
    "value": {
        "line1": "308 Eddy St",
        "city": "San Francisco",
        "state": "CA",
        "postal_code": "94102",
        "country_code": "USA"
    },
    "child_risk_values": [
        {
            "risk_parameter_id": "rsk_km7k_gl_class_code_by_location",
            "instance": "location_2.gl_class_code_by_location_1",
            "value": null,
        }
    ]
},

As you can see above:

  • The parameters for location have instances of location_1 and location_2 respectively.
  • The class code below location_1 has an instance of location_1.gl_class_code_by_location_1.
  • The class code below location_2 has an instance of location_2.gl_class_code_by_location_1.

When rendering this on screen, you’ll want to want to visually place the child parameters below the parent, and you may want to hide the 2nd instance of all creates_array: true parameters. All of these instructions are documented in our guide to building a front end.

Let’s assume that the class code for manufacturing, which takes place at the location in Los Angeles, is 53731. We want to make sure that we submit 53731 as the class code with the instance location_1.gl_class_code_by_location_1, nested below the location with the instance location_1.

Your PUT request to /application/{application_id} should look like this:

Copied
{
    "risk_parameter_id": "rsk_yor8_location",
    "instance": "location_1",
    "value": {
        "line1": "3325 Wilshire Blvd",
        "city": "Los Angeles",
        "state": "CA",
        "postal_code": "90010",
        "country_code": "USA"
    },
    "child_risk_values": [
        {
            "risk_parameter_id": "rsk_km7k_gl_class_code_by_location",
            "instance": "location_1.gl_class_code_by_location_1",
            "value": null,
        }
    ]
},
{
    "risk_parameter_id": "rsk_yor8_location",
    "instance": "location_2",
    "value": {
        "line1": "308 Eddy St",
        "city": "San Francisco",
        "state": "CA",
        "postal_code": "94102",
        "country_code": "USA"
    },
    "child_risk_values": [
        {
            "risk_parameter_id": "rsk_km7k_gl_class_code_by_location",
            "instance": "location_2.gl_class_code_by_location_1",
            "value": null,
        }
    ]
}

How Instances are Generated

Each instance is automatically generated by Herald. The instance value has a relevant description based on the question, and a number based on its instance in the series. Submitting 4 individual values for location would automatically assign the instances location_1, location_2, location_3, and location_4.

If a parameter that can support multiple values is nested below a parent parameter that can have multiple values, the instance will have the parents instance as a prefix. For example, an applicant can have multiple locations with multiple class codes at each location. If the applicant has performs work across 2 industries at their second location, the class codes would have an instance of location_2.gl_class_code_by_location_1 and location_2.gl_class_code_by_location_2 respectively.

You can read the full list of parameters that have instances, and their instance names, in this document.

You do not have to submit instance in your request. Submitting this value will be ignored by Herald.