List Item Expression - Toolbox

Hi All,

I was working with the toolbox plugin and I have to say I am very impressed with the list item expression function. Great job @mishav!

I have a question about whether or not something I am trying to do is possible for this. For example, lets say that I have a data structure that looks like the following:

{
  "composite": {
    "name": "Material X",
    "layers": {
      "layer1": {
        "amount": 12,
        "type": {
          "name": "polycarbonate A",
          "subcomponents": {
            "subcomponent1": {
              "name": "sodium hydroxide",
              "amount": 30
            },
            "subcomponent2": {
              "name": "diphenoxide",
              "amount": 8
            }
          }
        }
      },
      "layer2": {
        "amount": 10,
        "type": {
          "name": "polycarbonate B",
          "subcomponents": {
            "subcomponent1": {
              "name": "sodium hydroxide",
              "amount": 26
            },
            "subcomponent2": {
              "name": "diphenoxide",
              "amount": 9
            }
          }
        }
      }
    }
  }
}

Composites are composed of layers in varying amounts. There are situations in which a user would like to see the total amount of a particular subcomponent of all layers in a composite material. For instance, the amount of sodium hydroxide in Material X. Different composites have varying amounts of layer, which have different amounts of subcomponents, which are stored as items in a list. What I ultimately would like to do is multiply the amount of the sub component in a unit of the layer, by the amount of the layer that is in a given composite, and then to retrieve the sum for all layers. Something like this:

Thing: Do a search for Composites
list expression = field(“layers”, “amount”) * field(“layers”, “type”,“subcomponents”,“amount”)
list expression:sum

The problem is, I am unable to filter the subcomponents by name as far as I can tell. I.e. sometimes, one would want the total amount of sodium hydroxide and other time they would want the total amount of diphenhydride.

I would appreciate any thoughts on whether or not this is possible and how I would go about doing this.

1 Like

Have you tried your luck with the Advanced setting inside of a filter after you Do a Search For?

I had tried to think of a way to structure it that would allow me to do that. The problem is that I am searching for composites (the top level thing) but need to filter a list of things that are nested within another list of things that belong to the composite. One possible route may be if I create an intermediate object on an ad hoc basis that does include both of those data points within a single “thing”. Then I could filter it based on the name of the sub component and then run the operation. I could see it getting out of hand though and exponentially multiplying the amount of data being stored by the app.

How did you go with this, @ryanellman ? Is it possibly worth storing some levels of the structure as a JSON blob, rather than have so many database links?

I ended up coming up with a work around that seems like it works but still has some shortcomings. What I do is create a temporary list that stores only the relevant info in a flatter structure so the calculation can be performed. I am unfamiliar with working with json in bubble though. Do you have some info on how that works. I think I am thinking of it too much as a relational database still. I would love it if we were able to see the database’s actual structure and write SQL queries for some tasks.