google.script.run.withSuccessHandler is not working

2,151 views
Skip to first unread message

Pravalika Salla

unread,
Feb 22, 2023, 6:14:55 AM2/22/23
to Google Apps Script Community
Hi ,

The app is created with Google AppScript & Sheets, it has been used for several years now but went down, the issue found is google.script.run.withSuccessHandler is not working, it shows an error Uncaught TypeError: Cannot read properties of undefined (reading 'run').

We needed some help 

Thanks & Regards,
S.Pravalika

Damien GOACOLOU

unread,
Feb 22, 2023, 6:20:18 AM2/22/23
to Google Apps Script Community
Hi, 
Do you use google.script.run.withSuccesshandler function ?

Pravalika Salla

unread,
Feb 22, 2023, 6:21:58 AM2/22/23
to google-apps-sc...@googlegroups.com
hi, 

Yes i use, google.script.run.withSuccessHandler function

S.Pravalika

"Ce message et toutes les pièces jointes (ci-après le "message") sont établis à l'intention exclusive de ses destinataires et sont confidentiels. Si vous recevez ce message par erreur, merci de le détruire et d'en avertir immédiatement l’expéditeur. Toute utilisation de ce message non conforme à sa destination, toute diffusion 
ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. L'internet ne permettant pas d'assurer l'intégrité de ce message, nous déclinons toute responsabilité au titre de ce message, dans l’hypothèse où il aurait été modifié."

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/AeFPgvizP1o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/cb79636c-4dbe-4cb4-8210-d7529b76547an%40googlegroups.com.

Damien GOACOLOU

unread,
Feb 22, 2023, 6:22:49 AM2/22/23
to Google Apps Script Community
It's difficult to help you without to show your code.

Pravalika Salla

unread,
Feb 22, 2023, 6:25:40 AM2/22/23
to google-apps-sc...@googlegroups.com
Sample code:

 $(document).ready(function ()
    { 
   var saveField = $('#save').val;
     $('#savereport').on('click'function(){
   if( !$('#save').val().trim().length)
    {
    //alert("No NAME entered to SAVE");
      document.getElementById('errorMsgs').innerHTML="No Report NAME provided to SAVE!";
      $"#emailDialog3" ).dialog('open');
 }
    else
    {
    var formValues = $("#save").serializeArray();
    var newValues = {};
    formValues.forEach(function(x){
    newValues[x.name] = x;  
    console.log('newvalues'newValues[x.name])      
    });
    
   var parameterList=params();
   console.log("PL"parameterList)
   var filterList=params1();
   console.log('FL'filterList);
   var filterList1=params2();
   console.log('FL1'filterList1);
   var filterList2=params3();
   console.log('FL2'filterList2);
    var filterList3=params4();
   if(parameterList=="")
   {
   //alert("No Columns selected to SAVE!");
      document.getElementById('errorMsgs').innerHTML="No Columns selected to SAVE!";
      $"#emailDialog3" ).dialog('open');

  return;
   }
   if(filterList=="")
   filterList=null;
    if(filterList2=="")
   filterList2=null;
    if(filterList1=="")
   filterList1=null;
    if(filterList3=="")
   filterList3=null;
   google.script.run
        .withSuccessHandler(function(){
           google.script.run.withSuccessHandler(showMenu)
                .getMenuListFromSheet();   
           $"#save" ).val("");
           }).addRowToSpreadsheet(newValues,parameterList,filterList,filterList1,filterList2,filterList3); 
 
 }
        });
      
           
    })
image.png



Damien GOACOLOU

unread,
Feb 22, 2023, 6:27:44 AM2/22/23
to Google Apps Script Community
What's the code of the  getMenuListFromSheet's function ?
You don't change name of tab or something like that ?

Pravalika Salla

unread,
Feb 22, 2023, 6:30:00 AM2/22/23
to google-apps-sc...@googlegroups.com
no, we didn't change any name of Tab


cbmserv...@gmail.com

unread,
Feb 22, 2023, 1:18:26 PM2/22/23
to google-apps-sc...@googlegroups.com

You will need to show us the server side code of this. That is where the failure is.

 

The function: getMenuListFromSheet specifically.

 

Most likely the cause is some data element in that spreadsheet has been deleted.

Sample code:

 

 

 

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAMHuw2vzSBvV%2BZgLYJTKg_B-fVHqOwEGe3pgCvN_wBGwKmmNKQ%40mail.gmail.com.

Pravalika Salla

unread,
Feb 23, 2023, 5:07:08 AM2/23/23
to google-apps-sc...@googlegroups.com
Hi,

folders in a drive everything checked, google.script.run.withSuccessHandler is not working for this several years code only, for others it's working fine

/*TO GET THE REPORT NAMES*/
function getMenuListFromSheet() {
  var lc = ss.getLastRow();
  return ss.getRange(21lc - 11).getValues();
}

CBMServices Web

unread,
Feb 23, 2023, 12:52:44 PM2/23/23
to google-apps-sc...@googlegroups.com
Ok the server side function looks good.

Having a second look at your client side code and I don't see that you provided the code for function showMenu.

Where is the code for that function?


Edouard Rossignol

unread,
Feb 25, 2023, 11:43:31 AM2/25/23
to Google Apps Script Community
Hello,

Same problem here. The issue appears when trying to pass a hash table through google.script.run.withSuccessHandler

Here is a minimal example to highlight the issue

Code.gs

function doGet() {
return HtmlService.createHtmlOutputFromFile('Index');
}

function returnValueifTrue_arrayIfFalse(myBool) {
if(myBool){
return 667
}
else{
return {'a' : 667};
}
}

Index.html

<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function onSuccess1(numUnread) {
var div = document.getElementById('output1');
div.innerHTML = 'Result is ' + numUnread;
}
function onSuccess2(numUnread) {
var div = document.getElementById('output2');
div.innerHTML = 'Result is ' + numUnread;
}

google.script.run.withSuccessHandler(onSuccess1)
.returnValueifTrue_arrayIfFalse(true);
google.script.run.withSuccessHandler(onSuccess2)
.returnValueifTrue_arrayIfFalse(false);
</script>
</head>
<body>
<div id="output1"></div>
<div id="output2"></div>
</body>
</html>


Expected result (used to work)
Result is 667
Result is {'a' : 667}
Actual result
Result is 667
Result is [object Object]

Same issue happens with CacheService

Please escalate !!
Regards,
ER

Edouard Rossignol

unread,
Feb 25, 2023, 12:51:40 PM2/25/23
to Google Apps Script Community
Ignore my previous post. I do have the issue, but it is not properly reproduced in the previous examples. Cheers

cbmserv...@gmail.com

unread,
Feb 25, 2023, 2:38:53 PM2/25/23
to google-apps-sc...@googlegroups.com

Eduoard,

 

First, please note that there are no Google employees on this discussion group. This is merely a discussion group for developers who work on Google AppsScript. If you need to open a ticket with Google, then use this website to create a ticket or search for a ticket if you think one was opened: https://issuetracker.google.com/

 

Second, the display you are showing is actually correct. Your server function returnValueifTrue_arrayIfFalse

Is returning an object and the html code is showing it is an object.

    return {'a' : 667};

 

 

If you want to display the text instead, then either change code in your function to return a string or do a stringfy in the HTML side to convert object to string.

 

      function onSuccess2(numUnread) {

        numUnread = JSON.stringfy(numUnread);

        var div = document.getElementById('output2');

        div.innerHTML = 'Result is ' + numUnread;

      }

 

Hope this helps.

Edouard Rossignol

unread,
Feb 26, 2023, 3:57:33 AM2/26/23
to Google Apps Script Community
Hello,

Thank you for your reply. As I wrote in my own response, the issue I have noted is not properly described in my post, and in the end unrelated to the OP's post. Sorry for that.
The issue does exist with google.script.run.withSuccessHandler used in the context of google.charts.load('upcoming', {'packages': ['vegachart']});  which is currently broken.

If anyone ends up on this post for this reason, 
google.charts.load('50', {'packages': ['vegachart']}) works

Cheers,
ER

Brett Grear

unread,
Feb 26, 2023, 5:38:35 AM2/26/23
to Google Apps Script Community
Is there time or date columns in your spreadsheet data. You can't pass these back into client side without stringifying then first. 
Try .getDisplayValues() instead of .get values() although this may break other things depending on your dataset

Pravalika Salla

unread,
Feb 27, 2023, 10:57:06 PM2/27/23
to google-apps-sc...@googlegroups.com
function showMenu(menuItems
  {
  var list = $('#menu');
list.find('option').remove();  
  for (var i = 0i < menuItems.lengthi++) 
  {
    list.append('<option>' + menuItems[i] + '</option>');
  }
}


cbmserv...@gmail.com

unread,
Feb 28, 2023, 12:28:54 AM2/28/23
to google-apps-sc...@googlegroups.com

The showMenu function looks ok. But the error is basically indicating that it can not find it. So you should make sure this function is defined correctly in the same html file and preferably before where it is being called.

 

Also, not sure why you have nested google.script.run commands. You should segregate them and then see if error goes away.

Message has been deleted

cbmserv...@gmail.com

unread,
Mar 8, 2023, 3:18:43 PM3/8/23
to google-apps-sc...@googlegroups.com

One issue that may get many in dealing with webapps is the publish step.

 

Anytime you do a change to the code on the server side or on the client side, you need to publish a new version of the code or else none of the changes take effect.

 

I am not sure this is your case or not,  as you have not shared any code with us here. But certainly one thing to check closely.

 

From: 'Jeremiah Martinez' via Google Apps Script Community <google-apps-sc...@googlegroups.com>
Sent: Wednesday, March 8, 2023 7:54 AM
To: Google Apps Script Community <google-apps-sc...@googlegroups.com>
Subject: Re: [Apps-Script] Re: google.script.run.withSuccessHandler is not working

 

Any update on this? I'm following closely as I am also having the same issue (all of a sudden, like within the last couple days).

 

In one instance withSuccessHandler correctly receives the parameter from the server-side function. In another instance, withSuccessHandler doesn't receive the parameter at all.  Both instances run the same server-side function and both instances use the same client-side function to pass the same parameter to the server-side function.  Logging the parameter right before returning back to withSuccessHandler shows me that the parameter is correct on the server side in both instances before being passed back to client-side.

 

This is totally bizarre. 

Brett Grear

unread,
Mar 8, 2023, 3:51:59 PM3/8/23
to google-apps-sc...@googlegroups.com
What is being passed back to the client from the server?
Is it values from a spreadsheet?
Do these values from the spreadsheet include Dates or Times?
Dates and times can not be passed back in a successHandler but it does not result in an error, it just passes back null.




On Wed, 8 Mar 2023 at 15:53, 'Jeremiah Martinez' via Google Apps Script Community <google-apps-sc...@googlegroups.com> wrote:
Any update on this? I'm following closely as I am also having the same issue (all of a sudden, like within the last couple days).

In one instance withSuccessHandler correctly receives the parameter from the server-side function. In another instance, withSuccessHandler doesn't receive the parameter at all.  Both instances run the same server-side function and both instances use the same client-side function to pass the same parameter to the server-side function.  Logging the parameter right before returning back to withSuccessHandler shows me that the parameter is correct on the server side in both instances before being passed back to client-side.

This is totally bizarre. 

On Monday, February 27, 2023 at 10:28:54 PM UTC-7 cbmserv...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages