【问题标题】:Function: Error stackTraceLimit: 10 - JavaScript, Google AppScript功能:错误 stackTraceLimit: 10 - JavaScript、Google AppS 脚本
【发布时间】:2021-02-13 02:58:55
【问题描述】:

请原谅我的愚蠢问题,我真的是这个编码世界的新手。

我在一个页面上运行了一个谷歌应用脚​​本,它从不同的工作表中提取数据。到目前为止的代码运行良好,只是它跳过了几行代码并给了我一个 { [Function: Error] stackTraceLimit: 10 } 。这个跳过部分非常重要,感谢你们能提供帮助。

谢谢。我将在下面发布整个代码。

    const bookAId         = 'xxxxxxxxxxxxx'; // ssId of book A
    const bookBId         = 'yyyyyyyyyyyyy'; // ssId of book B
    const sheetA          = 'RS_Tharalsdson' // name of sheet in book A containing sheet names
    const deadlineRange   = 'G3'; // the cell in book B sheet i that you want to copy - deadline
    const pmsRange        = 'A3' // the cell in book B sheet i that you want to copy - pms
    
    const pmsOnq          = 'onq';
    const pmsFosse        = 'fosse'
    const pmsGalaxy       = 'galaxylightspeed'
    const pmsOpera        = 'opera'
    
    const fileFormatCol   = 4 // column D
    const fileFormatRow   = 6 // first row containing file formats
    const operaCol        = 6 // column F
    const operaRow        = 6 // first row of opera file formats
    
    const subCol          = 5 // submission method column of fosse,onq and galaxy
    const subRow          = 6 // submission starting row of fosse,onq and galaxy
    const subColOpr       = 4 // opera submission col
    const subRowOpr       = 6// opera submission starting row
    
    function getFileFormat(){
      const ssA                   = SpreadsheetApp.openById(bookAId);
      const sA                    = ssA.getSheetByName(sheetA);
      const sheetNames            = sA.getRange('G2:G').getValues().reduce((names, row) =>  row[0] !== '' ? names.concat(row[0]) : names ,[]);
      const ssB                   = SpreadsheetApp.openById(bookBId);
      const fileFormatsFromBookB  = []; // collect the values you find in each sheet
      const submissionMethods       = []; //collect all the submission methods in each sheet   
            
      for (const sheetName of sheetNames) {
        const sheet = ssB.getSheetByName(sheetName);
        
        if (!sheet){
            fileFormatsFromBookB.push(['Sheet Not Found'])
            continue;
        } 
        
        const pmsCell   = sheet.getRange(pmsRange).getValue();
        var array1      = [{}];
        var string2     = pmsCell;
        array1          = string2.split(/[:\n]/);      
        var pms         = array1[1];
        pms             = pms.replace(/\s+/g, '').toLowerCase();
        console.log(sheetName)
        console.log(pms)
        
    
        if(pms==pmsOpera){
          const fileFormatRange = sheet.getRange(operaRow, operaCol, sheet.getLastRow(), 1);
          const fileFormats     = fileFormatRange.getValues();
          var col0              = fileFormats.map(function(value,index) { return value[0]; });     
          const distinct        = (value, index, self) =>{ return self.indexOf(value)===index;}
          var unq               = col0.filter(distinct).toString();
          fileFormatsFromBookB.push([unq]);
    
//ERROR SKIPS BELOW CODE//
          const subMethodsRange = sheet.getRange(subRowOpr, subColOpr, sheet.getLastRow(), 1);
          const subMethods      = subMethodsRange.getValues();
          var col1              = subMethods.map(function(value,index) { return value[0]; });     
          const distinct1       = (value, index, self) =>{ return self.indexOf(value)===index;}
          var unqSub            = col1.filter(distinct1).toString();
          
          submissionMethods.push([unqSub]);
          console.log(Error)
          
        }
    
        if (pms==pmsOnq || pms==pmsFosse || pms==pmsGalaxy) {
    
          const fileFormatRange = sheet.getRange(fileFormatRow, fileFormatCol, sheet.getLastRow(), 1);
          const fileFormats     = fileFormatRange.getValues();
          var col0              = fileFormats.map(function(value,index) { return value[0]; });     
          const distinct        = (value, index, self) =>{ return self.indexOf(value)===index;}
          var unq               = col0.filter(distinct).toString();
          fileFormatsFromBookB.push([unq]);
    
          const subMethodsRange = sheet.getRange(subRow, subCol, sheet.getLastRow(), 1);
          const subMethods      = subMethodsRange.getValues();
          var col1              = subMethods.map(function(value,index) { return value[0]; });     
          const distinct1       = (value, index, self) =>{ return self.indexOf(value)===index;}
          var unqSub            = col1.filter(distinct1).toString();
          submissionMethods.push([unqSub]);
    
        } 
        
        //else {
        //  submissionMethods.push(["__"]);
        //}
       sA.getRange(2, 10, fileFormatsFromBookB.length, 1).setValues(fileFormatsFromBookB); // paste all of the values you collected into the paste range you specified in book
       sA.getRange(2, 11, submissionMethods.length, 1).setValues(submissionMethods); // paste submission methods:unique values
      }
    }

【问题讨论】:

  • 我能问你的问题吗? 1、{ [Function: Error] stackTraceLimit: 10 }的错误出现在哪里? 2. 我能问一下你的剧本目标吗?
  • 嗨,我注释的代码中发生错误 //ERROR SKIPS BELOW CODE// up to 'submissionMethods.push([unqSub]);'。我在代码中没有看到任何错误。但有些东西在那里。目的是我试图从两个不同的范围中获取值,并且它们在不同的工作表中的两个不同范围内。由于这涉及大量数据,我试图自动触发功能,因此工作表将以 100% 的准确度自动化。

标签: javascript google-apps-script google-sheets error-handling runtime-error


【解决方案1】:

我设法修复了错误。这实际上是一个错字。如果搜索没有返回任何内容,我还没有将值推送到搜索数组。代码如下。

 if (!sheet){
        fileFormatsFromBookB.push(['Sheet Not Found'])
        submissionMethods.push(['Sheet Not Found'])//THIS FIXED THE ISSUE
        continue;
    } 

感谢大家的帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-13
    • 1970-01-01
    相关资源
    最近更新 更多