Can any of you tell me how I can query an Optional Bool
field value in Navigator frontend-config.js?
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 isNone
- the corresponding serialization of
x
if their value isSome 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"
}
@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.
@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",
}
],
Thank you @Robert_Autenrieth and @bernhard, works perfectly, this time I need the custom column version, but also noted the filter code