Jump to content

Google Apps Script / Javascript Map Function

Hi Everyone,

 

I've had a lot of help doing something in the Google Sheets editor and have also posted this in the Google Apps Script forum but so far, no one's been able to help and I'm too clueless to help myself. If someone could point me the right direction or help me in any way, it would be much appreciated.

 

Here's my issue. This is all on a spreadsheet online so the .getRange refers to the columns. The functions work perfectly fine and this whole code works fine as is but the problem is that if I have values returning from function concatCustomer() and concat() but NOT concatOther(), the code stops before concat() can be ran. 

 

To reiterate, if A2:A has values and E2:E has values returning while C2:C has no values returning due to input, the function for A2:A will run and the code will stop as C2:C won't return values and thus, E2:E's values will no longer be run. 

 

Is there an easy way to solve this? Someone in the Google Apps Script forum said to use {};{};{}; but I'm not sure how to input that. Thanks! 

 

Oh and just to add what updateConcatCustomer() is, this function is part of a dropdown menu so that other users can click on the dropdown menu, select the function and be able to update the spreadsheet and have the spreadsheet return the values. Hope that explains it! 

 


 

function updateConcatCustomer () {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var values = concatCustomer().map(function (e) {return [e];});
  var sheet = ss.getSheetByName("Calc");
  sheet.getRange('A2:A').clearContent();
  sheet.getRange(2, 1, values.length, 1).setValues(values);
  var values2 = concatOther().map(function (i) {return [i];});
  sheet.getRange('C2:C').clearContent();
  sheet.getRange(2, 3, values2.length, 1).setValues(values2);
  var values3 = concat().map(function (k) {return [k];});
  sheet.getRange('E2:E').clearContent();
  sheet.getRange(2, 5, values3.length, 1).setValues(values3);

}

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

What is being returned by `concatOther` when there is no values?  Is it an empty array, or null/undefined? 
It might help to post the code for that function aswell. 
Trying to call map on null or undefined will cause a TypeError, that could be whats stopping the rest of the code from running.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×