title: Why am I getting, "Uncaught TypeError: getEnumerator is not a function"?
body: <p>In my Sharepoint 2010 Web Part, I've got this Javascript:</p>
  
  <pre><code>function getListItemID(username, payeename, oList) {
      var arrayListEnum = oList.getEnumerator();
  </code></pre>
  
  <p>...which is called by this:</p>
  
  <pre><code>function upsertPostTravelListItemTravelerInfo1() {
  var clientContext = SP.ClientContext.get_current();
  var oList =   
    clientContext.get_web().get_lists().getByTitle('PostTravelFormFields');
  
  this.website = clientContext.get_web();
  currentUser = website.get_currentUser();
  
  var itemCreateInfo = new SP.ListItemCreationInformation();
  this.oListItem = oList.addItem(itemCreateInfo);
  
  var travelersEmail = $('traveleremail').val();
  
  /* If this is an update, the call to getListItemID() will return a val; otherwise (an insert), get from newly instantiated ListItem.  */
  listId = getListItemID(currentUser, travelersEmail, oList);
  </code></pre>
  
  <p>I got the basis for this code from <a href="https://stackoverflow.com/questions/33047426/how-can-i-determine-if-a-sharepoint-listitem-exists-based-on-a-couple-of-known-v">here</a>.</p>
  
  <p>But got the err listed above ("<em>Uncaught TypeError: oList.getEnumerator is not a function</em>");</p>
  
  <p>One answer said I needed to add this:</p>
  
  <pre><code>&lt;script type="text/javascript" src="/_layouts/15/sp.js" &gt;&lt;/script&gt;
  </code></pre>
  
  <p>...which I changed from "15" to "14" as that is the folder/version we're using.</p>
  
  <p>That not only didn't work, but was unrecognized. I then found a clue <a href="https://sharepoint.stackexchange.com/questions/92082/uncaught-typeerror-cannot-read-property-get-current-of-undefined">here</a>, namely to add this:</p>
  
  <pre><code>$(document).ready(function () { ExecuteOrDelayUntilScriptLoaded(CustomAction, "sp.js"); });
  </code></pre>
  
  <p>...but that only an error prior to the one already shown, namely, "<em>Uncaught ReferenceError: CustomAction is not defined</em>"</p>
  
  <p>So what's the scoop? What is required to getEnumerator(), or otherwise retreive the ID val I need?</p>
  
  <p>Here is the full code to that method, to show what I'm trying to accomplish, and how:</p>
  
  <pre><code>function getListItemID(username, payeename, oList) {
    var arrayListEnum = oList.getEnumerator();
  
    while (arrayListEnum.moveNext()) {
       var listItem = arrayListEnum.get_current();
  
       if (listItem.get_item("ptli_formPreparedBy") === username &amp;&amp;
           listItem.get_item("ptli_TravelersEmail") === payeename &amp;&amp;
           listItem.get_item("ptli_formCompleted") == false) {
         return listItem.get_id();    
       }
     }
     return '';
  }
  </code></pre>
  
  <h2>UPDATE</h2>
  
  <p>When I tried this (first and third lines are new):</p>
  
  <pre><code>&lt;SharePoint:ScriptLinkID="ScriptLink1" Name="SP.js" runat="server" OnDemand="false" LoadAfterUI="true" Localizable="false"&gt;&lt;/SharePoint:ScriptLink&gt;
  &lt;script type="text/javascript"&gt;
      SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);
  </code></pre>
  
  <p>...which was inspired by a cat <a href="https://social.msdn.microsoft.com/Forums/en-US/fb8fc1bc-785c-4c87-96e6-21fe8e769cdd/get-list-via-client-object-model-error-uncaught-typeerror-cannot-read-property-getbytitle-of?forum=sharepointdevelopmentprevious" rel="nofollow noreferrer">here</a>, I got, "<em>System.Web.HttpParseException was unhandled by user code
    Message=The server tag is not well formed.</em>"</p>
  
  <p>Personally, I don't think Sharepoint is very well formed. But that's (right) beside the point (no pun intended).</p>