Use fragments to determine if all statuses are set to Done in monday.com board


Get Started

Not the template you're looking for? Browse more.

About the template


This template demonstrates how monday.com fragments can be used to get column specific values. In particular, it checks if all the status columns for an item are set to "Done". If so, it will archive the item. Get started to learn more.

About ScriptRunner Connect


What is ScriptRunner Connect?

ScriptRunner Connect is an AI assisted code-first (JavaScript/TypeScript) integration platform (iPaaS) for building complex integrations and automations.

Can I try it out for free?

Yes. ScriptRunner Connect comes with a forever free tier.

Can I customize the integration logic?

Absolutely. The main value proposition of ScriptRunner Connect is that you'll get full access to the code that is powering the integration, which means you can make any changes to the the integration logic yourself.

Can I change the integration to communicate with additional apps?

Yes. Since ScriptRunner Connect specializes in enabling complex integrations, you can easily change the integration logic to connect to as many additional apps as you need, no limitations.

What if I don't feel comfortable making changes to the code?

First you can try out our AI assistant which can help you understand what the code does, and also help you make changes to the code. Alternatively you can hire our professionals to make the changes you need or build new integrations from scratch.

Do I have to host it myself?

No. ScriptRunner Connect is a fully managed SaaS (Software-as-a-Service) product.

What about security?

ScriptRunner Connect is ISO 27001 and SOC 2 certified. Learn more about our security.

Template Content


README

Scripts

TypeScriptUseFragmentsToCheckStatusColumns
When any column changes

README


๐Ÿ“‹ Overview

This template demonstrates how monday.com fragments can be used to get column specific values. In particular, it checks if all the status columns for an item are set to "Done". If so, it will archive the item.

๐Ÿ–Š๏ธ Setup

  • Configure the API Connection and Event Listener by creating a connector for monday.com, or use a existing one.

๐Ÿš€ Usage

Update a status column for an item in a monday.com board. After successfully processing the event, the item will be archived if its value in every status column is set to the designated "Done" value.

API Connections


TypeScriptUseFragmentsToCheckStatusColumns

import { UpdateColumnValueEvent } from '@sr-connect/monday/events';
import { StatusValueReturnType } from '@managed-api/monday-core/definitions/columnValueFragments/statusValue';
import Monday from "./api/monday";

/**
 * Each column type in Monday contains different kinds of information. For example, a timeline column will have `from` and `to` dates,
 * but a number column will not. To access these fields, a fragment can be added to the request. This will add the fields to any columns
 * of the matching type, and ignore them for other columns.
 *
 * In this example, a `StatusValue` fragment is used to access the `is_done` field, which is only available in status columns.
 */
export default async function (event: UpdateColumnValueEvent, context: Context): Promise<void> {
    if (Object.keys(event).length === 0) {
        console.error('This script is designed to be triggered externally or manually from the Event Listener. Please consider using Event Listener Test Event Payload if you need to trigger this script manually.');
        return;
    }
    // Extract necessary parameters from the event
    const { pulseId } = event.event;

    // Check if the necessary parameters are present in the event
    if (!pulseId) {
        throw Error("Pulse ID not present in the event");
    }

    const resp = await Monday.Item.getItems({
        args: {
            ids: [pulseId],
        },
        fields: {
            column_values: {
                // Normal fields will be returned for all column_values, regardless of the column's type.
                fields: {
                    __typename: true,
                },
                // Fragment fields will only be returned for columns of the appropriate type.
                // If the column is of a different type, the field will not exist.
                fragments: {
                    // In this example we're using the StatusValue fragment to get information specific to status columns.
                    StatusValue: {
                        is_done: true,
                    },
                },
            },
        },
    });

    // Check item is retrieved
    if (resp.data.items?.length != 1) {
        throw Error("Expected item not found");
    }

    let allDone: boolean = true;
    // Loop over each column.
    resp.data.items[0].column_values.forEach(c => {
        // If __typename matches the fragment name then it is a status column.
        if (c.__typename == 'StatusValue') {
            // Once we know the entry referes to a status column, it can be safely cast to a StatusValue to access the status-specific fields.
            const statusColumn = c as StatusValueReturnType;
            // Check if any status columns are not set to the "Done" value.
            if (!statusColumn.is_done) {
                allDone = false;
            }
        }
    });

    // Archive the item if all status columns are set to done.
    if (allDone) {
        Monday.Item.archiveItem({
            args: {
                item_id: pulseId,
            },
            fields: {
                id: true,
            }
        });
    }
}
Documentation ยท Support ยท Suggestions & feature requests