Friday 5 April 2019

Google Sheets Scripts - A basic helloworld example

I've written this note after an issue has been noted due to one of my scripts not working in Google Sheets.   And this is a pretty helpful way of troubleshooting any issues.   To work backwards from this. 

Troubleshooting Google Scripts
If you've got an issue you'll see "#NAME?" 

Hover over this and you'll see a report of the issue.




One way to run a test is to build up you're function from scratch .  

Let's just run a 'hello world ' example.
So let's use a function call 'SwapStringTest' .

we can call this using a SUM in the cell A1


=SwapStringTest("Hello World")
In our Scripts ( Tools > Scripts )

We'd use

function SwapStringTest(string){
 
 return  string
 }
This will simple print out 'Hello World' into our first cell.



From here I could pass every section of the function I had and found that the  STARTDATE was producing a NaN value.

to fix is I used
$start = end_date_obj.setDate(0);
 
// for the month prior to
 
$end = end_date_obj.setDate(1);

No comments: