title: Hard Line Break in Google Apps Script (Google Docs with Google Form Field to create new bullet in bulleted list)
body: <p>I'm using Google Forms to feed a Google Doc (via Google Sheets), and in this Google Doc I have a pre-existing bulleted list. I would like to enter code that will add another bullet to the list. </p>
  
  <p>My approach has been to add a <code>###newLine###</code> tag to the end of the last pre-filled bullet in the form. I then used <code>replace.Text(###newLine###)</code> in GAS, and then added <code>'\n'</code> for a new line. </p>
  
  <p>The problem is that this <code>'\n'</code> inserts a soft line break (like a Shift+Enter), and it doesn't create a new bullet. It just creates a new line under the prior bullet. I have tested within the doc by adding/removing the bullet associated with the above paragraph, and it is clear that this new line is associated with the above paragraph. What I would like is a a hard line break (like simply pressing Enter) which will create a new bullet.</p>
  
  <p>Here's what the code looks like:</p>
  
  <pre><code>body.replaceText('###newLine###', '\n' + 'Produces a soft (shift+enter) line break.');
  </code></pre>
  
  <p>Also tried:</p>
  
  <pre><code>body.appendParagraph(). 
  </code></pre>
  
  <p>This attached to the end of the body and didn't seem to replaceText.</p>
  
  <pre><code>var insertPar = body.insertParagraph(21, 'test insert paragraph');
  body.replaceText('###newBullet###', insertPar);
  </code></pre>
  
  <p>This would put it in the right spot but not as part of the list.</p>
  
  <pre><code>var listItemTest = body.appendListItem('#listItemTest#');
  body.replaceText('###newBullet###', listItemTest);
  </code></pre>
  
  <p>This appended a numbered list to the end of the body but would not replace text or add to the existing bulleted list.</p>
  
  <p>08-03-19, I tried the following, per Jescanellas's assistance. It works perfectly in the original test doc I provided, but I can't port it over to other docs. I think that's because I'm somehow failing to get the right data to attach it to the list at the right level, but I'm not sure where I'm messing up.</p>
  
  <pre><code>  var formDataEntered = functionName.values[11] || ''; //This var is retrieved from the sheet attached to a form. It's the submitted data.
    var listItem = body.getListItems(); //We're getting the list.
  
     for (var i = 0; i &lt; listItem.length;i++){ //We're creating a loop here.
       var item = body.getListItems()[i]; //This gets the list and applies the loop to it.
  
       if ((item.findText('###bulletTestPlaceholder###')) &amp;&amp; (formDataEntered != '')){ //The ###bulletTestPlaceholder### is just a placeholder in the doc where I want to insert the bullet. Your purpose with the item.findText is to identify the list level we're going for - NOT to use the text itself as a placeholder and replace the text. 
  
          var index = body.getChildIndex(item); //You're getting all the data about var item (where we got the list and applied the loop).
          var level = item.getNestingLevel();  //This gets the nesting level of var item. I'm wondering if this might be the issue as it's not specific to the findText('###bulletTestPlaceholder###')?
          var glyph = item.getGlyphType(); //This gets the bullet type. 
  
          body.insertListItem((index + 1), formDataEntered).setNestingLevel(level).setGlyphType(glyph); //This is the location in the list where teh bullet will be placed. It also sets the nesting level and glyph type. I've tried playing with the nesting level using integers, but that doesn't fix it.
  
          item.replaceText('###bulletTestPlaceholder###',''); //removes '###bulletTestPlaceholder###' text after it's no longer needed.
  
          break; //stops the loop from looping multiple times.
  
       } else if ((item.findText('###bulletTestPlaceholder###')) &amp;&amp; (formDataEntered == '')) {
         item.replaceText('###bulletTestPlaceholder###',''); //removes '###bulletTestPlaceholder###' text and avoids new line if no formDataEntered
       }
  
    }
  </code></pre>