Upsert item into a monday.com board


Get Started

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

About the template


Updates a monday.com board with newly created items created from an external source such as another board and updates the status to allow items to be synced across different sources. 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

TypeScriptUpsertItems
When an item is created

README


๐Ÿ“‹ Overview

You can insert or update an existing item on your main board from an external trigger, such as when a new item is created in another board and it's status is updated.
This helps to start syncing items from other sources into a single monday.com board.

๐Ÿ–Š๏ธ Setup

Follow these steps to configure the template with your board:

  1. Open the Upsert a created item from external sources into main monday.com board template.
  2. Click Create a Workspace on the top right corner of the screen.
  3. Review the Workspace name, Description and Add to a team fields.
    You can change these if needed.
  4. Click Create.
  5. On the left side of the screen, under API Connections, select Complete API Connection Setup.
  6. Select your monday.com connector in the Uses connector field.
  7. Click Save.
  8. On the left side of the screen under Event Listeners, select Complete Event Listeners Setup.
  9. Select the When an item is created event for the Listener Event Type field.
  10. Select Use existing script.
  11. Select UpsertItems from the Use existing script dropdown.
  12. Select your monday.com connector in the Uses connector field.
  13. Click Save.
  14. Navigate to Parameters and and edit the following parameters:
    • TARGET_BOARD_ID - Enter the board ID that you want to upsert items to.
    • PROJECT_STATUS_ID - Enter the ID of the Status column value to update.
    • LABEL - Enter the status you want to set for items.

๐Ÿš€ How to Use

Create a new item in a secondary monday.com board.

Intial parent board status

Add new item in child

This template will update the status of all existing items in your main board with the same summary value to Working on it.

Updated parent board

If no items exist on your main board with this matching summary, then a new item will be created with a status of Working on it.

Another item added to child board

Item added to parent board

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

You could also modify this script to sync for items when an item is created in another tool like Jira or Service Now.

API Connections


TypeScriptUpsertItems

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

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 { TARGET_BOARD_ID, PROJECT_STATUS_ID, LABEL } = context.environment.vars;

    // Extract required parameters from the event
    const { pulseName, pulseId, boardId } = event;

    // Fetch all items from your main board that match the new item summary with their current status
    const getItemsFromBoard = await Monday.ItemsPage.getItemsPageByColumnValues({
        args: {
            board_id: TARGET_BOARD_ID,
            // This column searches for a case-insensitive match of the entire name text value.
            columns: [{ column_id: "name", column_values: [pulseName] }]
        },
        fields: {
            items: {
                fields: {
                    id: true,
                    name: true,
                    column_values: {
                        fragments: {
                            StatusValue: {
                                text: true
                            }
                        },
                        fields: {
                            id: true
                        }
                    }
                }
            }
        }
    });
    
    const { items } = getItemsFromBoard.data.items_page_by_column_values;

    // Update the status of created item
    await Monday.Column.changeMultipleColumnValues({
        args: {
            board_id: boardId,
            item_id: pulseId,
            column_values: {
                [PROJECT_STATUS_ID]: LABEL
            }
        },
        fields: {
            id: true
        }
    });

    // Update the status of matching items
    if (items.length) {
        for (const item of items) {
            const { text } = item.column_values.find(status => status.id === PROJECT_STATUS_ID) as unknown as { id: string, text: string };

            text !== LABEL && await Monday.Column.changeMultipleColumnValues({
                args: {
                    board_id: TARGET_BOARD_ID,
                    item_id: Number(item.id),
                    column_values: {
                        [PROJECT_STATUS_ID]: LABEL
                    }
                },
                fields: {
                    id: true
                }
            });
        }

    } else {
        // Create a new item and set the status
        await Monday.Item.createItem({
            args: {
                board_id: TARGET_BOARD_ID,
                item_name: pulseName,
                column_values: {
                    [PROJECT_STATUS_ID]: { label: LABEL }
                }
            },
            fields: {
                id: true
            }
        });
    }
}
Documentation ยท Support ยท Suggestions & feature requests