Fetch items that have a specific value in a connected board column

Is it possible to fetch items that contain a specific value from a connected board column inside a board?

I would like to retrieve all items and the item info that have a specific value in the connected board column for example:

Fetch all items that have “John Doe” in the connected column from a clients board.

It does not appear you can directly search it using items_page, and board_relation columns are not yet supported by items_page_by_column_value. But, you can use items_page to search a mirror column, so at least that works!

You would need to do something like the following then manually filter client side on items[].linked_items[].name to find any items by name.

{
  boards(ids: 5508116697){
    items_page(limit: 50) {
      items {
        id
        name
        linked_items (linked_board_id: "5508144514",  link_to_item_column_id: "link_to_board") {
          id
          name
        }
      }
    }
  }
}

An alternate if you don’t want to control which connected board’s items, but instead want every connected board’s items to be returned:

{
  boards(ids: 5508116697){
    items_page(limit: 50) {
      items {
        id
        name
        column_values (ids: "link_to_board") {
          ... on BoardRelationValue {
            linked_items {
              id
              name
            }
          }
        }
      }
    }
  }
}
1 Like

Thank you so much for the response Cody. Yes I think that could work, I can just filter them on my end based on the item’s values returned I think. So the second query would retrieve all items from a board that have a connected column value in them correct?
Also, the first query would fetch items based on the mirror column value?
PS: sorry for these questions without testing this first, I’m new to monday ap development I’m and trying to see if what I need is possible before I start creating an app.

1 Like

both queries return all board items (no other way when you’re looking for the item name on a connect board column). The first query lets you pick which connected board AND which connect board column you want to see connected items from.

Board A has a connect board column, this is the board you want to retrieve from. Query 1 will return all the connected items from board b (specified by id) that are connected to on the “link_to_board” column (by id).

Query 2, will rather return all connected items on the “link_to_board” regardless of which board they are on, board B, or board C, D, E through ZE.

If you want to search for a value on a mirror column, then you can use a regular item pages query. This will help out since it only returns items that have an actual match. Unfortunately today you can’t use board_relation columns in items page filters.

{
  boards(ids: 5508116697) {
    items_page(
      query_params: {rules: [{column_id: "mirror_1", compare_value: ["John Smith"], operator: any_of}]}
    ) {
      items {
        id
        name
        column_values(ids: "mirror1") {
          ... on MirrorValue {
            mirrored_items {
              linked_item {
                id
                name
              }
            }
          }
        }
      }
    }
  }
}

Look at the documentation for items_page to understand how to paginate results since you will likely need it.

1 Like

Thank you so much for the help Cody, I eventually ended up with a structure that looks like this:

query GetConnectedItems {
    boards(ids: <id>) {
      items_page(limit: 50) {
        items {
          id
          name
          column_values(ids: "link_to_board") {
            ... on BoardRelationValue {
              linked_items {
                id
                name
                column_values {
                  text
                }
              }
            }
          }
        }
      }
    }
  }

And I can succesfully retrieve all the column data from all connected items in every item within the main board.

I jsut have one more question if I may. Is there a way I can separate the connected items by their corresponding connected board? Since items connected in my main board have 3 different sources, I would like to handle these separately since the column structure is different I may need to handle the incoming with the use of an id or something similar that can help me separate the items.

1 Like

Yup

query GetConnectedItems {
    boards(ids: <id>) {
      items_page(limit: 50) {
        items {
          id
          name
          column_values(ids: "link_to_board") {
            ... on BoardRelationValue {
              linked_items {
                id
                name
                board {
                  id
                }
                column_values {
                  text
                }
              }
            }
          }
        }
      }
    }
  }

Excellent! Thank you so much.

1 Like

Just an FYI this query is as deep as you can go in a single query. Don’t try to get anything deeper on linked_items[].board, or linked_items[].column value (like returning the column{title,settings_str} in addition).

Also i would recommend always returning the id in column_values. If you request multiple column_values by ID (multiple BoardRelation columns?) you’ll need to be able to see which is which in your results.

Also I’d keep the limit small (100?) instead of the max of 500, this is a pretty hefty query and you don’t want to have a timeout (60s) inadvertently.

Thanks for the tips. I did see that monday has a limit on query depth so I did structure the query accordingly, plus its really not a dealbreaker since I can just hardcode those values if needed. Also yeah I’m not trying to overload the server with huge requests and reasonable limits will be placed for sure. Thanks again for the help!

1 Like