Lookup - smbc-digital/form-builder Wiki

Lookup

The 'Lookup' property can be used on Radio, Select and Checkbox elements to retrieve Options from a different source. There are currently 3 types of Lookup: Answer Lookup, Dynamic Lookup, and Reusable Lookup.

Answer Lookup

Answer Lookup works along side the Retrieve External Data Action, it allows you to use a saved answer from an external request.

To use Answer Lookup, you need to add the 'Lookup' property follow by '#' and 'TargetQuestionid' ( see below ).

DSL properties

Property Type Required Default Value Description
Lookup string value must start with #{TargetQuestionid}

Example (including the associated Page Action to Retrieve External Data

"PageActions": [
        {
          "Type": "RetrieveExternalData",
          "Properties": {
            "TargetQuestionId": "isValidLookup",
            "HttpActionType": "Post",
            "PageActionSlugs": [
              {
                "Environment": "local",
                "URL": "https://localhost:44399/api/v1/AdditionalBin?isValid={{radio}}",
                "AuthToken": "TestToken"
              }
            ]
          }
        }
```current page json
"Elements": [
        {
          "Type": "Checkbox",
          "Lookup": "#isValidLookup",
          "Properties": {
            "Label": "Select your choices",
            "QuestionId": "whatBin",
          }
        }

Dynamic Lookup

Dynamic Lookup works by retrieving options from an external source where the options will differ based on previous form answers. The URL can parse previous answers as parameters in the same way as Retrieve External Data does by enclosing the QuestionId in curly brackets eg. {{questionId}}. The retrieved options will NOT be stored in the answers, they are retrieved each time the page loads.

To use Dynamic Lookup, you need to set the 'Lookup' property to 'dynamic', and add an array of 'LookupSources' for each environment, to include the environment name, the provider (json is the only option currently), the url, and the auth token.

DSL properties

Property Type Required Default Value Description
Lookup string Set to 'dynamic'

Example

"Elements": [
        {
          "Type": "Checkbox",
          "Lookup": "dynamic",
          "Properties": {
            "Label": "Select your choices",
            "QuestionId": "whatBin",
            "LookupSources": [
              {
                "EnvironmentName": "local",
                "Provider": "Json",
                "URL": "https://localhost/api/v1/lookup?question={{questionId}}",
                "AuthToken": "Token"
              }
            ]
          }
        }

Reusable Lookup

Reusable Lookup allows the reuse of options saved in the json provider for certain element types list below. If a reusable lookup and options are declared the reusable lookup options will be appended after the options declared within the form itself.

To use Reusable Lookup, you need to set the 'Lookup' property to the name of the Reusable Lookup file stored in the json provider.

DSL properties

Property Type Required Default Value Description
Lookup string Set to the name of the file eg. 'councillors'

Example (including an additional option not in the Reusable Lookup file)

"Elements": [
        {
          "Type": "Checkbox",
          "Lookup": "councillors",
          "Properties": {
            "Label": "Select your councillor",
            "QuestionId": "councillor",
            "Options": [
              {
                "Text": "Extra councillor",
                "value": "extra"
              }
            ]
          }
        }