When an item is added to monday.com board set the priority to critical if the timeline is less than configured period


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, so when a new item is added to monday.com board, the priority is set to critical if the timeline column value is less than configured period. 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

TypeScriptOnMondayWhenAColumnChanges
When a column changes

README


๐Ÿ“‹ Overview

This template demonstrates how to build an automation in monday.com, so when a new item is added to monday.com board, the priority is set to critical if the timeline column value is less than configured period.

๐Ÿ–Š๏ธ Setup

To configure this script to run against your selected board, complete the following steps below:

  1. Configure the API Connection by providing a monday.com connection that gives you access to the board against which you'd like to run this script.
  2. Configure an Event Listener for the When a column changes event by creating a connector for monday.com or use an existing one to execute the script when a Timeline column value changes.
  3. Navigate to Parameters and and edit the following parameters:
    • PRIORITY_COLUMN_ID - Should hold the ID of the Priority column that you want to set. See our guide here on how to find a column id.
    • PRIORITY_VALUE_NAME - Should hold the text name for the priority you want to set (Note: if priority names include icons or spaces, also include them here).
    • CRITICAL_THRESHOLD_DAYS - Should contain the number of days that when set in a timeline column will cause the item to be set to the priority name you entered above.

๐Ÿš€ How to use

When your chosen timeline column is changed, the template will log out the from, to and updated_at date values. It will then set the Priority to the value you choose if the time between the from and to dates is less than or equal to three days.

Steps to trigger the script:

  1. Select a from and to date value by clicking your timeline column and choosing the dates from the calendar window.
    Select date range
  2. The listener setup earlier will then trigger.
  3. Refer to the ScriptRunner Connect console output to see a log of the timeline date values.
  4. Refer to the item you edited from the Monday board and validate the priority changes if you selected a timeline of three days or less.
    Priority updated

๐Ÿ–Š๏ธ How to modify the script

You could modify the script to use a different date range or set multiple different priority values for multiple different date ranges.

API Connections


TypeScriptOnMondayWhenAColumnChanges

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

/**
 * This is an example of how to parse the data stored in a Monday Timeline column.
 */
export default async function(event: UpdateColumnValueEvent, 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;
    }

    // Extract necessary parameters from the event
    const { pulseId, boardId, columnId } = event.event;

    // Check if the necessary parameters are present in the event
    if (!pulseId) {
        throw Error('Pulse ID not present in the event');
    }
    if (!boardId) {
        throw Error('Board ID not present in the event');
    }
    if (!columnId) {
        throw Error('Column ID not present in the event');
    }

    // Get the column data for the item.
    const itemsQueryResult = await Monday.Item.getItems({
        args: {
            ids: [pulseId]
        },
        fields: {
            column_values: {
                args: {
                    ids: [columnId]
                },
                fields: {
                    id: true
                },
                fragments: { // use fragments to define the sub-fields we want returned for the Timeline columns value
                    TimelineValue: {
                        from: true,
                        to: true,
                        updated_at: true
                    }
                }
            }
        }
    });

    // Convert the column value to the expected `TimelineValueReturnType` type for a Timeline field.
    // We simply request the first index of the `column_values` list here as that is the only column we requested in the above `getItems` API call.
    const timelineColumnValue = itemsQueryResult.data.items[0].column_values[0] as TimelineValueReturnType;
    const { from, to, updated_at } = timelineColumnValue;
    if (!from || !to) {
        console.log('Script exiting as Timeline column value was cleared');
        return;
    }

    // log out the Timeline columns `from`, `to` and `updated_at` values
    console.log(`From Date: ${from}\nTo Date: ${to}\nUpdated Date: ${updated_at}`);

    const { PRIORITY_VALUE_NAME, PRIORITY_COLUMN_ID, CRITICAL_THRESHOLD_DAYS } = context.environment.vars;
    
    const threshold_date = new Date(to);
    // subtract 1 less than `CRITICAL_THRESHOLD_DAYS` as for example:
    // (new Date("2024-07-25T00:00:00+00:00") - 3) does not consider the final day (i.e. the 25th) as a full day when it is set to midnight,
    // however the Monday Timeline column does consider it a full day.
    threshold_date.setDate(threshold_date.getDate() - (CRITICAL_THRESHOLD_DAYS - 1));

    // if the timeline `from` date is less than the threshold days before the timelines `to` date set the priority to the `PRIORITY_VALUE_NAME` value
    if (new Date(from) >= threshold_date) {
        await Monday.Column.changeSimpleColumnValue({
            args: {
                board_id: boardId,
                item_id: pulseId,
                column_id: PRIORITY_COLUMN_ID,
                value: PRIORITY_VALUE_NAME
            },
            fields: {
                column_values: {
                    fields: {
                        id: true
                    }
                }
            }
        });
    }
}
Documentation ยท Support ยท Suggestions & feature requests