Query record from external database and automatically populate form fields?

What would be the best way to query an external database and populate all the fields in a form?

Here are the steps I've completed so far:

1. External database connected as a data source

2. CDT created and entity has been successfully mapped to data source

3. Form has been created using the CDT as rule inputs, and with each form field's "Display Value" and "Save Input To" set to the respective field in the CDT.

In the screenshot below, the Barcode field is the primary key in the CDT and the external database. I want to be able to scan in a barcode number and then automatically populate the remaining form fields with the data record from the external database.

What should be my next step?

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    You will probably want to put a query to the data store in the saveInto of the Barcode ID field (set to execute only when the barcode ID is non-null), saving the results of your query into your local / rule input variable.

    You also probably want to look into dynamically setting certain fields as editable or read-only depending on whether you want users to be able to change the values of the other fields after the initial query (and if you do, you probably want to restrict their ability to edit the prior barcode ID to prevent any changes from being overwritten in a way that surprises the user).

  • This is a good answer - to add to it, your SAIL might look something like this:

    a!barcodeField(
      label: "Barcode",
      labelPosition: "ABOVE",
      acceptedTypes: {},
      value: ri!item.id,
      saveInto: {
        ri!item.id,
        if(
          isnull(ri!item.id),
          {},
          a!save(
            target: ri!item,
            value: a!queryEntity(
              entity: cons!OSM_ITEM_ENTITY,
              query: a!query(
                filter: a!queryFilter(
                  field: "id",
                  operator: "=",
                  value: tointeger(save!value)
                ),
                pagingInfo: a!pagingInfo(
                  startIndex: 1,
                  batchSize: 1
                )
              )
            ).data
          )
        )
      },
      refreshAfter: "UNFOCUS",
      validations: {}
    )