Hi, I am trying to get the current status of a sch...
# suitescript
t
Hi, I am trying to get the current status of a scheduled script on my suitelet. But I can only get the first status. Is there anyway I can do it? What I tried so far is created a search that gets the scheduledscriptinstance and filter it by the scriptId then perform a loop.
Copy code
function checkingStatus(status) {

    if (outOfTime() && status != "COMPLETE") {
        status = getScheduledScriptStatus("customscript_mog_create_forecast_ss"); // CHANGE THE SCRIPT ID ON MOG ENV
    }

    return status;
}

function outOfTime() {
    return (context.getRemainingUsage() < 1000);
}

function getScheduledScriptStatus(scriptId) {

    var scheduledscriptinstanceSearch = getSearchResults("scheduledscriptinstance", null, [
        ["script.scriptid","is", scriptId], // "customscript_mog_create_forecast_ss"
        "AND",
        ["datecreated","within","today"]
    ], [
        new nlobjSearchColumn("datecreated").setSort(true),
        new nlobjSearchColumn("startdate"),
        new nlobjSearchColumn("enddate"),
        new nlobjSearchColumn("queue"),
        new nlobjSearchColumn("status"),
        new nlobjSearchColumn("mapreducestage"),
        new nlobjSearchColumn("percentcomplete"),
        new nlobjSearchColumn("queueposition")
    ], 1);

    var status = '';
    if (scheduledscriptinstanceSearch.length > 0) {

        var cols = scheduledscriptinstanceSearch[0].getAllColumns();

        for (var j = 0; j < scheduledscriptinstanceSearch.length; j++) {
            status = scheduledscriptinstanceSearch[j].getValue(cols[4]);
        }
    }

    return status;
}
c
Why are you watching/checking the script? Is it to run another process afterwards?
c
@Tyn Guardian How many rows is that search returning?
t
@Charles Halliday I am watching it so I can prompt on my SL that the saving is done @Clay Roper Currently its a 100+ records
c
@Tyn Guardian And you're only getting the status of the last row because you're overwriting
status
with every loop iteration?
t
yes.. But if there is a better approach. I am happy to know.
c
N/task module