SuiteScript – Submitting a Map Reduce Task Results to NO_DEPLOYMENT_AVAILABLE Error

When executing a Map/Reduce Script the error “NO_DEPLOYMENT_AVAILABLE” is thrown. This error is thrown if a script attempts to submit a new instance of a Map/Reduce Script Deployment into the queue that is still in progress. Below are two options using Suite Script 2.0 that can help to prevent the script from throwing the error.

Option A: Before submitting a task into the queue, run a Saved Scheduled Script Instance Search to check if there are any in progress jobs with the same script deployment internal ID:

Step 1. Create a Saved Search on the UI:

Navigate to Reports > Saved Searches > All Saved Searches > New

Select Scheduled Script Instance

Mark the Public checkbox

Add the following Filters under the Criteria subtab:

Script Deployment: Internal ID – any of – Internal ID of the Script Deployment record for Map/Reduce script

Status – none of – ‘Complete’, ‘Canceled’, ‘Failed’

Step 2. Run the Saved Search before submitting a task into the queue:

Before submitting the task into the queue, run the search created in Step 1. If the search returns result(s), the script will not submit an instance of the Map/Reduce script since there’s still one that is in progress.

var mySearch = search.load({‌
    id: 'customsearch_step1' //Please replace this with the Search's script ID
});

var searchResultCount = mySearch.runPaged().count;
if (searchResultCount > 0) {‌
    //Same with NO_DEPLOYMENT_AVAILABLE error. The task will not be submitted into the queue because same script deployment is still in progress
} else {‌
    //No in progress, submit the task
    var taskStatus = null;
    var stTaskId = scriptTask.submit();
    taskStatus = NSTask.checkStatus(stTaskId);
}

Option B: Create multiple Script Deployment records for the Map/Reduce script and reference a unique script deployment using the deployment property when creating a task. 

var scriptTask = NSTask.create({‌
    taskType: NSTask.TaskType.MAP_REDUCE,
    scriptId: mr_scriptId,
    deploymentId: 'customdeploy5',
    params: objScriptParamsToPass
});

Leave a comment

Your email address will not be published. Required fields are marked *