Get a specific cell value in a Google Spreadsheet Script










0















I am trying to modify a little script to email myself the results of a Google Form.
The script is working in its basic form, but I can't seem to be able to retrieve the value from a cell and copy it in the subject field.



Here is what I am trying:



var lastRow = SpreadsheetApp.getActiveSheet().getMaxRows();
var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValues();
var subject = "Todo List: " + title;


The script stops working though, when I do that :)
Any idea why? Thanks










share|improve this question




























    0















    I am trying to modify a little script to email myself the results of a Google Form.
    The script is working in its basic form, but I can't seem to be able to retrieve the value from a cell and copy it in the subject field.



    Here is what I am trying:



    var lastRow = SpreadsheetApp.getActiveSheet().getMaxRows();
    var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValues();
    var subject = "Todo List: " + title;


    The script stops working though, when I do that :)
    Any idea why? Thanks










    share|improve this question


























      0












      0








      0








      I am trying to modify a little script to email myself the results of a Google Form.
      The script is working in its basic form, but I can't seem to be able to retrieve the value from a cell and copy it in the subject field.



      Here is what I am trying:



      var lastRow = SpreadsheetApp.getActiveSheet().getMaxRows();
      var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValues();
      var subject = "Todo List: " + title;


      The script stops working though, when I do that :)
      Any idea why? Thanks










      share|improve this question
















      I am trying to modify a little script to email myself the results of a Google Form.
      The script is working in its basic form, but I can't seem to be able to retrieve the value from a cell and copy it in the subject field.



      Here is what I am trying:



      var lastRow = SpreadsheetApp.getActiveSheet().getMaxRows();
      var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValues();
      var subject = "Todo List: " + title;


      The script stops working though, when I do that :)
      Any idea why? Thanks







      google-apps-script google-sheets






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 28 '15 at 20:51









      Mogsdad

      33.5k1290194




      33.5k1290194










      asked Jun 16 '14 at 16:19









      alemuralemur

      8681534




      8681534






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Never tried this but looking at 'title' you have ...getValues() suggesting a collection of titles which you assign to a single variable what does getValues()[0] give you. Try indexing into that collection maybe..






          share|improve this answer























          • Nope, the email notification still won't work - thanks anyway :)

            – alemur
            Jun 16 '14 at 16:39


















          0














          getValues() will return a 2-dimensional Javascript array (so I think getValues()[0][0] should work); but as you are wanting to retrieve a single value from a single cell, you may as well just use getValue().



          var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValue();






          share|improve this answer























          • Unfortunately my script gets stuck when I add it. Here is the full script as it is now: gist.github.com/akmur/b7c5ce803122a96e65b7 If I add var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValue(); it just won't work, the debugger gets stuck at the "var title" line.

            – alemur
            Jun 17 '14 at 8:10











          • I got it to do what I need by adding: subject = "Discussion: " + e.namedValues['* Project Name']; in the for loop. Not really a good solution I think, but it works

            – alemur
            Jun 17 '14 at 10:52










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24248097%2fget-a-specific-cell-value-in-a-google-spreadsheet-script%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Never tried this but looking at 'title' you have ...getValues() suggesting a collection of titles which you assign to a single variable what does getValues()[0] give you. Try indexing into that collection maybe..






          share|improve this answer























          • Nope, the email notification still won't work - thanks anyway :)

            – alemur
            Jun 16 '14 at 16:39















          0














          Never tried this but looking at 'title' you have ...getValues() suggesting a collection of titles which you assign to a single variable what does getValues()[0] give you. Try indexing into that collection maybe..






          share|improve this answer























          • Nope, the email notification still won't work - thanks anyway :)

            – alemur
            Jun 16 '14 at 16:39













          0












          0








          0







          Never tried this but looking at 'title' you have ...getValues() suggesting a collection of titles which you assign to a single variable what does getValues()[0] give you. Try indexing into that collection maybe..






          share|improve this answer













          Never tried this but looking at 'title' you have ...getValues() suggesting a collection of titles which you assign to a single variable what does getValues()[0] give you. Try indexing into that collection maybe..







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jun 16 '14 at 16:32









          AndrewAndrew

          1,9151120




          1,9151120












          • Nope, the email notification still won't work - thanks anyway :)

            – alemur
            Jun 16 '14 at 16:39

















          • Nope, the email notification still won't work - thanks anyway :)

            – alemur
            Jun 16 '14 at 16:39
















          Nope, the email notification still won't work - thanks anyway :)

          – alemur
          Jun 16 '14 at 16:39





          Nope, the email notification still won't work - thanks anyway :)

          – alemur
          Jun 16 '14 at 16:39













          0














          getValues() will return a 2-dimensional Javascript array (so I think getValues()[0][0] should work); but as you are wanting to retrieve a single value from a single cell, you may as well just use getValue().



          var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValue();






          share|improve this answer























          • Unfortunately my script gets stuck when I add it. Here is the full script as it is now: gist.github.com/akmur/b7c5ce803122a96e65b7 If I add var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValue(); it just won't work, the debugger gets stuck at the "var title" line.

            – alemur
            Jun 17 '14 at 8:10











          • I got it to do what I need by adding: subject = "Discussion: " + e.namedValues['* Project Name']; in the for loop. Not really a good solution I think, but it works

            – alemur
            Jun 17 '14 at 10:52















          0














          getValues() will return a 2-dimensional Javascript array (so I think getValues()[0][0] should work); but as you are wanting to retrieve a single value from a single cell, you may as well just use getValue().



          var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValue();






          share|improve this answer























          • Unfortunately my script gets stuck when I add it. Here is the full script as it is now: gist.github.com/akmur/b7c5ce803122a96e65b7 If I add var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValue(); it just won't work, the debugger gets stuck at the "var title" line.

            – alemur
            Jun 17 '14 at 8:10











          • I got it to do what I need by adding: subject = "Discussion: " + e.namedValues['* Project Name']; in the for loop. Not really a good solution I think, but it works

            – alemur
            Jun 17 '14 at 10:52













          0












          0








          0







          getValues() will return a 2-dimensional Javascript array (so I think getValues()[0][0] should work); but as you are wanting to retrieve a single value from a single cell, you may as well just use getValue().



          var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValue();






          share|improve this answer













          getValues() will return a 2-dimensional Javascript array (so I think getValues()[0][0] should work); but as you are wanting to retrieve a single value from a single cell, you may as well just use getValue().



          var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValue();







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jun 16 '14 at 23:11









          AdamLAdamL

          15.3k34344




          15.3k34344












          • Unfortunately my script gets stuck when I add it. Here is the full script as it is now: gist.github.com/akmur/b7c5ce803122a96e65b7 If I add var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValue(); it just won't work, the debugger gets stuck at the "var title" line.

            – alemur
            Jun 17 '14 at 8:10











          • I got it to do what I need by adding: subject = "Discussion: " + e.namedValues['* Project Name']; in the for loop. Not really a good solution I think, but it works

            – alemur
            Jun 17 '14 at 10:52

















          • Unfortunately my script gets stuck when I add it. Here is the full script as it is now: gist.github.com/akmur/b7c5ce803122a96e65b7 If I add var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValue(); it just won't work, the debugger gets stuck at the "var title" line.

            – alemur
            Jun 17 '14 at 8:10











          • I got it to do what I need by adding: subject = "Discussion: " + e.namedValues['* Project Name']; in the for loop. Not really a good solution I think, but it works

            – alemur
            Jun 17 '14 at 10:52
















          Unfortunately my script gets stuck when I add it. Here is the full script as it is now: gist.github.com/akmur/b7c5ce803122a96e65b7 If I add var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValue(); it just won't work, the debugger gets stuck at the "var title" line.

          – alemur
          Jun 17 '14 at 8:10





          Unfortunately my script gets stuck when I add it. Here is the full script as it is now: gist.github.com/akmur/b7c5ce803122a96e65b7 If I add var title = SpreadsheetApp.getActiveSheet().getRange(lastRow, 2).getValue(); it just won't work, the debugger gets stuck at the "var title" line.

          – alemur
          Jun 17 '14 at 8:10













          I got it to do what I need by adding: subject = "Discussion: " + e.namedValues['* Project Name']; in the for loop. Not really a good solution I think, but it works

          – alemur
          Jun 17 '14 at 10:52





          I got it to do what I need by adding: subject = "Discussion: " + e.namedValues['* Project Name']; in the for loop. Not really a good solution I think, but it works

          – alemur
          Jun 17 '14 at 10:52

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24248097%2fget-a-specific-cell-value-in-a-google-spreadsheet-script%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          What does pagestruct do in Eviews?

          Dutch intervention in Lombok and Karangasem

          Channel Islands