Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

Im currently just learning Javascript and making an App for my Club. One of the members has asked for a page which will display all members that have checked in that day.

So far this is the code i have, but its returning the error "The script completed but the return value is not the supported type" But when it doesnt find any Row with todays date. it returns my Else statement of "no entries found"

Here is what i have coded so far below:

<pre>// Commences Check input
function check(date){
      var in_time = Utilities.formatDate(new Date(), 'Etc/GMT', 'yyyy-MM-dd');
      var successId = 0;
      var rows = dailySheet.getDataRange().getValues();

      var filteredRows = rows.filter(function(row){
        if (row[4] === in_time) {
          successId = Number(successId)+1;
          return row;
        }
        
      })
      
      if(successId == 1){
      
        var i;
        
        for (i = 0; i < filteredRows.length; i++) {
         return ContentService.createTextOutput(filteredRows[i][1]+" "+filteredRows[i][2]).setMimeType(ContentService.MimeType.TEXT)+ "<br>";
        } 
      
      
        
      }
      
      else{
        return ContentService.createTextOutput("No Entries Found").setMimeType(ContentService.MimeType.TEXT);
      } 
      
     
  
 }



This is what the excel sheet looks like.
https://imgur.com/ubah3eM

No entries Found.
https://imgur.com/ABgMVCG

Error.
https://imgur.com/MiBpG5e

What I have tried:

i have tried recoding it but to no avail.

This works but only when there is one entry of todays date, when there are more than one entry it displays No entries found instead of the multiply entries.

var ss = SpreadsheetApp.openByUrl("https://docs.");
var dailySheet = ss.getSheetByName("daily_attendance");
var memberSheet = ss.getSheetByName("membership");

// Commences function to retrieve action variable from app.
function doPost(e){
  var action  = e.parameter.action;
  
  if(action == "check"){
    return check(e);
  }
      
}

// Commences Check Code input
function check(e){
      var in_time = Utilities.formatDate(new Date(), 'Etc/GMT', 'yyyy-MM-dd');
      var successId = 0;
            
      var rows = dailySheet.getDataRange().getValues();
      var filteredRows = rows.filter(function(row){
        if (row[4] === in_time) {
          successId = Number(successId)+1;
          return row;
        }
        
      });
      
      
      
      if(successId == 1){
      
        return ContentService.createTextOutput(filteredRows[0][2]+" "+filteredRows[0][3]).setMimeType(ContentService.MimeType.TEXT); 
      }
      
      else{
        return ContentService.createTextOutput("No Entries Found").setMimeType(ContentService.MimeType.TEXT);
      } 
      
     
  
 }
Posted
Updated 8-Feb-20 10:02am
v3
Comments
[no name] 8-Feb-20 18:27pm    
If this an Excel sheet, why aren't you using VBA? That's what it is designed for.
Mohibur Rashid 8-Feb-20 20:49pm    
he did not mention but he is using google doc and the class and functions are from google aps script https://developers.google.com/apps-script/reference/content/content-service
Mohibur Rashid 8-Feb-20 20:43pm    
i don't if this has anything to do, but you have `+ "<br>";` under your condition. this is in your first code. this is breaking your javascript

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900