Check Duplicates

📂 Interaction to identify and check duplicate entries.

1. Overview

This interaction serves to check for duplicates within a specific context. In this scenario, it operates with a text field, and whenever a user types a value that already exists in the system, an alert message will be displayed.

🚧

Important Note:

The alert serves as a notification but doesn't prevent the user from submitting the entry.

2. Example

This example shows how the interaction checks for duplicates in a specific field and provides feedback to the user through an alert message.

  1. It begins by requesting to retrieve entries with the specified criteria using C.api.listEntries. It is then extracted and stored in entryData.
  2. It checks if there is an entry matches the currentKeyValue:
    1. If such an entry is found, it displays an alert informing the user that the key number already exists, prompting them to enter a new one.
    2. If no matching entry is found, it logs a message indicating that the key number is unique.
async function handler(C) {
    try {
        const getEntries = await C.api.listEntries({
            internalId: "admedia-commercials",
            responseType: "iov",
            ignoreLimits: true,
        });

        const entryData = getEntries.entries;

        const currentKeyValue = C.getValue("1662670-key-number"); // get key number that is currently typed
        const entryWithSameKey = entryData.find(data => data["1662670-key-number"] === currentKeyValue);

        if (entryWithSameKey) {
            alert("This Key Number already exists, please type in new one");
        } else {
            console.log("Unique key number");
        }
    } catch (error) {
        console.error("Error:", error);
    }
}

📌 Need Help?

If you require assistance or encounter any issues, please don't hesitate to contact us for further support.