Skip to content
Discussions/App Development/`Optional Bool` field value in Navigator frontend-config.js?Forum ↗

`Optional Bool` field value in Navigator frontend-config.js?

App Development5 posts353 views2 likesLast activity Jun 2020
GY
gyorgybalazsiOP
Jun 2020

Can any of you tell me how I can query an Optional Bool field value in Navigator frontend-config.js?

RO
Robert_Autenrieth
Jun 2020

The following examples assume that you are familiar with the basics of frontend-config.js, and that you have a contract field

    active : Option Bool

In general, Option fields are serialized to:

  • null if their value is None
  • the corresponding serialization of x if their value is Some x

Option Bool is therefore serialized to either null, true, or false.


If you want to filter by the boolean field, use the following blocks. To only display contracts where the active field is Some True or Some False, use:

filter: [
  {
    field: "argument.active",
    value: "Some",
  }
],

To only display contracts where the active field is Some True, use:

filter: [
  {
    field: "argument.active.Some",
    value: "true",
  }
],

If you want to display the boolean value in a custom column, use the following block. It will print "N/A" for None values, "Yes" for Some True values, and "No" for Some False values.

{
  key: "argument.active",
  title: "Active",
  createCell: ({rowData}) => {
    const value = DamlLfValue.toJSON(rowData.argument).active;
    return {
      type: "text",
      value: value === null ? "N/A" : value === true ? "Yes" : "No"
    }
  },
  sortable: true,
  width: 80,
  weight: 3,
  alignment: "left"
}
BE
bernhard
Jun 2020
Robert_Autenrieth:

If you want to filter by the boolean field, use the following block. It will only display contracts where the active field equals to Some True .

filter: [
  {
    field: "argument.active",
    value: "true",
  }
],

@Robert_Autenrieth did you test this? I don’t think that’s true. Putting "None" and "Some", into value correctly filters those values that are None or Some. Putting in "true", "false" or "null" does not work for me.

RO
Robert_Autenrieth
Jun 2020

@bernhard Thanks for checking! I had initially tested my answer with a Bool field, and only realized later that the question is about Option Bool.

The code for the custom display is still correct. The code for filtering contracts is wrong, here are correct examples:

To only display contracts where the active field is Some True or Some False, use:

filter: [
  {
    field: "argument.active",
    value: "Some",
  }
],

To only display contracts where the active field is Some True, use:

filter: [
  {
    field: "argument.active.Some",
    value: "true",
  }
],
GY
gyorgybalazsi
Jun 2020

Thank you @Robert_Autenrieth and @bernhard, works perfectly, this time I need the custom column version, but also noted the filter code

← Back to Discussions