Receiving at least 20000+ errors when using lookup integration status

Hi,

I am getting a ton of errors when I am trying to just detect some flow that are not recently ran or skipped running due to a possible connection issue which probably happens for them to skip the schedule run and pose a risk for loss of data because of a schedule that was not properly ran.

This is my Javascript Pre hook script for that.

function checkFlowNotRunRecently(options) {
    const currentTime = Date.now();

    const flowId = String(options.data[0]._id || options.data[0]._integrationId || "Unknown ID");

    const flowName = options.data[0].name || "Unknown Flow";

    const traceKeyValue = String(options.data[0].io_custom_trace_key);

    const lastExecutedAt = options.lastExecutedAt || null;

    const flowDisabled = options.data[0].disabled;

    let resultmessage;
    let timeSinceLastRun = null;

    if (flowDisabled === true) {
        console.log("No Issue");
    }

    if (!lastExecutedAt) {
        resultmessage = true;
        throw new Error(`Flow "${flowName}" has NEVER been executed or lastExecutedAt is not available)`);
    }

    const lastExecutedTime = new Date(lastExecutedAt).getTime();
    timeSinceLastRun = currentTime - lastExecutedTime;
    const hoursSinceLastRun = (timeSinceLastRun / (60 * 60 * 1000)).toFixed(2);

    if (timeSinceLastRun >= 24 * 60 * 60 * 1000) {
        resultmessage = true;
        throw new Error(`Flow "${flowName}" has NOT run in the last 24 hours(last run: ${hoursSinceLastRun} hours ago)); } else { resultmessage = false; console.log("No Issue")`);
    }

    options.data.forEach((record) => {
        record.resultmessage = resultmessage;
        record.flowId = flowId;
        record.flowName = flowName;
        record.lastExecutedAt = lastExecutedAt;
        record.timeSinceLastRunMs = timeSinceLastRun;
        record.hoursSinceLastRun = hoursSinceLastRun;
    });

    return options.data;
}

FYI: I am just using console.log for those areas that need no actions, i just need a specific error thrown when one flow was not ran within 24 hours. Unfortunately, some flows are repetitively being thrown as an error, having major duplicates within. Any thoughts how to solve this issue?

Hooks run with a page of data, so by throwing an error you're throwing that error for the entire page of data and not just the record you want an error thrown for. You should review the preSavePage script stub on how to return errors:

To add, this script and flow setup look a bit off.

In a lookup step, the preSavePage hook only has access to the records returned by the lookup. It does not have access to the source record coming from your export. So if you are expecting fields from the export record (like lastExecutedAt), they will not be available here unless they are actually part of the lookup response.

Also, I generally would not hardcode data[0], but if you truly expect one lookup result per request, it is a common pattern and is probably fine. Many users do this instead of looping through data.

A couple other recommendations:

  • Make sure you have a trace key set on your export, and enable Auto-resolve errors on the flow. That way, if this runs again, duplicate errors will auto-resolve rather than piling up.
  • options.lastExecutedAt is not a real field. If lastExecutedAt exists at all, it would need to be on the lookup result itself (for example options.data[0].lastExecutedAt), or it may not be available at all if it is not returned by the lookup.

Hi @tylerlamparter !

Thanks for helping out! To be honest I am not really a good coder, just tried javascript to the extent of my working knowledge and a little bit of help from Celigo AI itself was the key to creating this script.

I’ll try your solution and let you know if this works. Thanks again!

No worries. I just about never code myself anymore, but to get a good AI response I always give the script stub and the sample input data so AI has full context for what is available. From there, you just tell it what you need to happen and test it out.