I have a map/reduce script that is only returning ...
# ask-stanley-ai
w
I have a map/reduce script that is only returning a suiteql in getInput data. Netsuite reports that the getInput fails and it skips the map & reduce stages. the summarizeContext.inputSummary does not contain any errors. I have verified the suiteql and it will return results
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems like the issue is with the Map/Reduce script getting stuck in the getInputData() stage. This could be due to a variety of reasons, including the complexity of the SuiteQL query, the size of the dataset being returned, or the performance of the environment. One of the users suggested that running a search on transactionLines without a date or type filter might not be considered a "small" dataset in many environments, and suggested adding a filter to the query to see if that changes anything. Another user suggested retrieving search/query results manually for better performance. They provided a helper function to get all results from a SuiteQL query, which uses pagination to retrieve the results in chunks of 5000 rows at a time. Here is the helper function provided:
Copy code
javascript
/**
 * Helper function to get all results from a SuiteQL query
 *
 * @param {string} sql The SuiteQL query to run
 * Code based on <https://timdietrich.me/blog/netsuite-suiteql-mapreduce-script/>
 *
 * @returns {*[]} The results of the query
 */
exports.getSuiteQLResults = (sql) => {
  const PAGE_SIZE = 5000;

  let rows = [];
  let paginatedRowBegin = 1;
  let moreRows = true;

  do {
    const paginatedSQL = `SELECT * FROM ( SELECT ROWNUM AS ROWNUMBER, * FROM (${sql} ) ) WHERE ( ROWNUMBER BETWEEN ${paginatedRowBegin} AND ${PAGE_SIZE})`;

    const queryResults = query.runSuiteQL({ query: paginatedSQL }).asMappedResults();

    rows = rows.concat(queryResults);

    if (queryResults.length < PAGE_SIZE) {
      moreRows = false;
    }

    paginatedRowBegin = paginatedRowBegin + 5000;
  } while (moreRows);

  return rows;
}
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.86163646
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.858424
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.856361
Please provide your feedback on this answer.