Set status of monday.com board item depending on permissions of the user who created the item


Get Started

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

About the template


This template demonstrates how to build an automation in monday.com to set the status of a board item depending if the person who created the item is admin or not. 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

TypeScriptOnMondayWhenAnItemIsCreated
When an item is created

README


๐Ÿ“‹ Overview

This template demonstrates how to build an automation in monday.com to set the status of a board item depending if the person who created the item is admin or not.

๐Ÿ–Š๏ธ Setup

  • Configure the API Connection and Event Listener by creating a connector for monday.com, or use an existing one.
  • Navigate to Parameters and change the STATUS_COLUMN_LABEL, STATUS_IF_ADMIN and STATUS_IF_NOT_ADMIN to values that work in your board.
  • Ensure that the status used for STATUS_IF_ADMIN and STATUS_IF_NOT_ADMIN exists as a valid status in column settings.

๐Ÿš€ Usage

Create a new item in a monday.com board, after successful event processing Status column should change depending on whether the person who created the item is an admin or not.

API Connections


TypeScriptOnMondayWhenAnItemIsCreated

import { CreateItemEvent } from "@sr-connect/monday/events";
import Monday from "./api/monday";

/**
 * This function sets the Monday.com board item status depending on whether the person who created the item is an admin or not.
 *
 * @param event Object that holds Issue Created event data
 * @param context Object that holds function invocation context data
 */
export default async function (event: CreateItemEvent, context: Context): Promise<void> {
    if (context.triggerType === 'MANUAL') {
        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;
    }

    const { userId, boardId, pulseId } = event.event;
    // Check if the required information is present in the event.
    if (!userId) {
        throw Error('User ID not present in the event');
    }
    if (!boardId) {
        throw Error('Board ID not present in the event');
    }
    if (!pulseId) {
        throw Error('Pulse ID not present in the event');
    }

    const { STATUS_COLUMN_LABEL, STATUS_IF_ADMIN, STATUS_IF_NOT_ADMIN } = context.environment.vars;

    // Get details of the user triggering the event.
    const userDetails = await Monday.User.getUsers({
        args: {
            ids: [userId],
        },
        fields: {
            is_admin: true,
        },
    });

    // Find the column ID of column to update.
    const board = await Monday.Board.getBoards({
        args: {
            ids: [boardId],
        },
        fields: {
            columns: {
                fields: {
                    id: true,
                    title: true,
                },
            }
        },
    });
    const columnId = board.data.boards[0].columns.find(c => c.title == STATUS_COLUMN_LABEL)?.id;
    if (!columnId) {
        throw new Error(`Could not find column with title ${STATUS_COLUMN_LABEL}`);
    }

    // Perform an action depending on if the user meeets some criteria.
    // In this example, the status of the item is set depending on if the user is an admin or not.
    if (userDetails.data.users[0].is_admin) {
        await setItemStatus(boardId, pulseId, columnId, STATUS_IF_ADMIN);
    } else {
        await setItemStatus(boardId, pulseId, columnId, STATUS_IF_NOT_ADMIN);
    }
}

async function setItemStatus(boardId: number, pulseId: number, columnId: string, status: string): Promise<void> {
    await Monday.Column.changeMultipleColumnValues({
        args: {
            board_id: boardId,
            item_id: pulseId,
            column_values: { [columnId]: status },
        },
        fields: {
            id: true,
        },
    });
}
Documentation ยท Support ยท Suggestions & feature requests