Fetching columns for Sub-items

Hi there,

I see that it is possible to have different columns for an item and sub-item as shown in this screenshot

But when I query columns in a board, I am only getting columns at the item level. How do I get columns corresponding to the sub-items?

Hi @kranthi_thoughtflow

This is because the subitems exist on a different board.

You need to make a query to retrieve the subitem column:

{
  boards(ids: boardid) {
    columns {
      id
      title
      settings_str
    }
  }
}

Note: that if you know the column id for the subitem column, you can enter this directly, it is generally just subitems but it can change, i.e. in my example the column id issubitems9. But I believe the title will always be “Subitems” which you can filter through in the results.

The settings_str will contain a value similar to this:

{
            "id": "subitems9",
            "title": "Subitems",
            "settings_str": "{\"allowMultipleItems\":true,\"itemTypeName\":\"column.subtasks.title\",\"displayType\":\"BOARD_INLINE\",\"boardIds\":[subitem_board_id]}"
},

You and then make a query using the subitem_board_id and query the columns to get the data you are looking for

Thanks for the prompt response @mitchell.hudson .
I am able to query the sub-item columns with this approach.

Hey @mitchell.hudson ,

I was able to access the subitem columns from the query editor, but when I try this from my app, I get the error
[{“message”:“Permission Denied! Your token doesn’t grant access to workspaces:read”}]

Even though my query does not request anything at the workspace level.

Also, does the monday.listen API work for changes on subitems?
I am not getting a callback when some subitem is changed.

Hi @kranthi_thoughtflow,

Could you please share the queries you’re using in your application?

Hi @alessandra
This is the query

export const MONDAY_ITEMS_WITH_SUBITEMS_QUERY = `query fetchItemsWithSubItems($itemIds:[Int],$subItemBoardIds:[Int]){
    boards(ids:$subItemBoardIds) {
      name
      workspace {
        id
      }
      columns{
        id
        title
        settings_str
        type
      }
    }
    items(ids:$itemIds){
      id
      name
      name
        column_values{
            id
            value
            additional_info
            type
        }
        subitems{
            id
            name
            column_values{
                id
                value
                additional_info
                type
            }
        }
    }
  }`

I am running this query after fetching all the items on the main board. The first input is the itemIds, and the second input is the boardIds corresponding to the subitems.
The first part of the query is to get the subitem columns, and the second part is to get the subitems from items.

This query started working well after I gave the workspace:read permission
I hope this is useful.

Hey @kranthi_thoughtflow

The reason you recieved the Permission error was due to you querying the workspace ID.

export const MONDAY_ITEMS_WITH_SUBITEMS_QUERY = `query fetchItemsWithSubItems($itemIds:[Int],$subItemBoardIds:[Int]){
    boards(ids:$subItemBoardIds) {
      name
      columns{
        id
        title
        settings_str
        type
      }
    }
    items(ids:$itemIds){
      id
      name
      name
        column_values{
            id
            value
            additional_info
            type
        }
        subitems{
            id
            name
            column_values{
                id
                value
                additional_info
                type
            }
        }
    }
  }`

Remove the workspace { id } from your query and you will be all good!

Oh. I missed that. Thanks a lot @mitchell.hudson :slight_smile: