title: run 2 similar javascripts on the same page
body: <p>I have 2 js files in the site asset directory on SPS2013. The code in each is similar.I need to use each script on the same SharePoint page in 2 content editor web parts (CEWP). I read on this thread "run 2 identical javascripts on the same page" that changing the method names resolves this kind of issue however, I have not managed to accomplish this. Each script runs as expected when there is only one CEWP on the page, when I add the other, the results from both end up in the same CEWP. </p>
  
  <p>I have renamed all the methods and the ID of the DIV that I am outputting to. I don't get any errors in the console. I would have thought that each script running inside a  tag would help but no luck. I'm not sure if this a SharePoint ism or a JS ism. Very new to JS so please keep it simple.</p>
  
  <p>I added both scripts below:</p>
  
  <p>Script 1</p>
  
  <pre><code>&lt;html&gt;
  &lt;style type='text/css'&gt; .tablewrapperEU { position: relative;  box-sizing: border-box; height:72px} .tableEU {display: table; } .rowEU { display: table-row; padding: 1px; } .cellEU { display: table-cell; border: none solid red; padding: 3px;} .cell.empty { border: none; width: 75px; } .cell.rowspanned {  position: absolute; top: 0;  bottom: 0; width: 75px; display: block; margin: 1px;} .contacts{ width: 72px; height: 72px;} .flag { width: 30px; height: 20px; }&lt;/style&gt;
  &lt;div class="myEUClass" id="divListItemsEU"&gt;&lt;/div&gt;&lt;/html&gt;
  
  
  
  &lt;script type="text/javascript"&gt;
  
  
  var $eu = jQuery.noConflict(true);
  
  
  $eu(function () {
  
  
  
      ExecuteOrDelayUntilScriptLoaded(retrieveEUListItems, "sp.js");
  
  
  
  
  });
  
  
  
  function retrieveEUListItems() {
  
      //get the cuurent location context of the page we are on
  
      var clientContextEU = new SP.ClientContext();
  
      // get the list/table from the web site where the page is located
  
      var oList = clientContextEU.get_web().get_lists().getByTitle('WhosWho');
  
      //
  
      //create a query to get all list items int he defult view
  
      var camlQueryEU = new SP.CamlQuery();
      camlQueryEU.set_viewXml("&lt;View&gt;&lt;Query&gt;" +
              "&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=\"ElementContactRegion\"/&gt;&lt;Value Type=\"Text\"&gt;EU&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;" +
          "&lt;/Query&gt;"+
          "&lt;/View&gt;");
      //create an array of list items
  
      this.collListItemEU = oList.getItems(camlQueryEU);
  
      //load the list items into context 
  
      clientContextEU.load(collListItemEU);
  
      //execute the query 
  
      clientContextEU.executeQueryAsync(
  
  
  
      Function.createDelegate(this, this.onQuerySucceeded),
  
  
  
      Function.createDelegate(this, this.onQueryFailed)
  
  
  
      );
  clientContextEU.dispose();
  
  
  }
  
  
  
  function onQuerySucceeded(sender, args) {
  
      // Might be worth starting with this here just to ensure the div is always clear before we start.
  
      $eu("#divListItemsEU").html('');
  
  
      var listEUItemInfoEU = '';
  
  
      var listItemEnumeratorEU = collListItemEU.getEnumerator();
  
      //Iterate results
  
  
      while (listItemEnumeratorEU.moveNext()) {
  
          // get the current looped item
  
          var oListItemEU = listItemEnumeratorEU.get_current();
  
  
          // get the userID from the lookup field
  
          var w = oListItemEU.get_item('ContactFullName').get_lookupId();
          var x = oListItemEU.get_item('ContactJobTitleFT');
          var y = oListItemEU.get_item('ContactRegion');
  
          // pass it into the get email method 
  
          getEUEmail(w,x, y, function(returnedValueEU) {
  
              //console.log(returnedValue[0])
  
              $eu("#divListItemsEU").append(
  
  
  
                      returnedValueEU[0]  + 
  
                      //oListItem.get_item('ElementContactFullName').get_lookupValue() +
  
                     // ' &lt;strong&gt;JobTitle:&lt;/strong&gt; ' + oListItem.get_item('ElementContactJobTitle').get_lookupValue() +
  
  
                      '&lt;br /&gt;');
  });
  
      }
  
  
  
      // display data
  
      $eu("#divListItemsEU").html(listEUItemInfoEU);
  
  }
  
  
  
  function onQueryFailed(sender, args) {
  
  
  
      alert('Request failed. ' + args.get_message() +
  
  
  
      '\n' + args.get_stackTrace());
  
  
  }
  
  
  
   function getEUEmail(userId, JT,  flag, callback) {
  
  
  
      var xEU = [];
  
      var contextEU = new SP.ClientContext();
  
      var webEU = contextEU.get_web();
  
      var user = webEU.get_siteUsers().getById(userId);
  
      contextEU.load(user);
  
  
  
      contextEU.executeQueryAsync(function() {
  
          //console.log(user.get_email());
  
          var yEU =   "&lt;div class='tablewrapperEU'&gt;" +
        "&lt;div class='tableEU'&gt;" +
          "&lt;div class='rowEU'&gt;" +
            "&lt;div class='rowspanned cell'&gt;" +
               ' &lt;img class="contacts" src="' + _spPageContextInfo.webServerRelativeUrl + '/_layouts/15/userphoto.aspx?size=M&amp;accountname='+ user.get_email()  +'"/&gt;' +
            "&lt;/div&gt;" +
            "&lt;div class='cellEU'&gt;" +
             user.get_title() +
            "&lt;/div&gt;" +
          "&lt;/div&gt;" +
          "&lt;div class='rowEU'&gt;" +
            "&lt;div class='empty cell'&gt;&lt;/div&gt;" +
            "&lt;div class='cellEU'&gt;" +
              JT +  
            "&lt;div class='cellEU'&gt;" +
           ' &lt;img class="flag" src="' + window.location.protocol + "//" + window.location.host   + '/SiteAssets/Images/'+ flag  +'.png"/&gt;' +
           //http://staging.intranet.ent.sys.element.com/SiteAssets/Images/EU.png
            "&lt;/div&gt;" +
          "&lt;/div&gt;" +
          "&lt;/div&gt;" +
        "&lt;/div&gt;" +
      "&lt;/div&gt;"
  
  
  
  
  
  
  
          xEU.push(yEU);
  
          callback(xEU);
  
  
  
      }
  
      , function() {
  
          console.log("error");
  
      });
  contextEU.dispose();
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Script 2</p>
  
  <pre><code>&lt;script src="/style%20library/javascript/intranet/jquery-1.7.1.min.js"&gt;&lt;/script&gt;
  
  &lt;style type='text/css'&gt; .tablewrapper { position: relative;  box-sizing: border-box; height:72px} .table {display: table; } .row { display: table-row; padding: 1px; } .cell { display: table-cell; border: none solid red; padding: 3px;} .cell.empty { border: none; width: 75px; } .cell.rowspanned {  position: absolute; top: 0;  bottom: 0; width: 75px; display: block; margin: 1px;} .contacts{ width: 72px; height: 72px;} .flag { width: 30px; height: 20px; }&lt;/style&gt;
  &lt;div class="myAllClass" id="divListItems"&gt;&lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
  
  var $sr = jQuery.noConflict(true);
  
  
  $sr(function () {
  
      ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");
  
  });
  
  
  
  function retrieveListItems() {
  
      //get the cuurent location context of the page we are on
  
      var clientContext = new SP.ClientContext();
  
      // get the list/table from the web site where the page is located
  
      var oList = clientContext.get_web().get_lists().getByTitle('WhosWho');
  
      //create a query to get all list items int he defult view
  
      var camlQuery = new SP.CamlQuery();
  
          camlQuery.set_viewXml("&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=\"ElementContactRegion\"/&gt;&lt;Value Type=\"Text\"&gt;US&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;" +
          "&lt;/Query&gt;"+
          "&lt;/View&gt;");
  
  
      //create an array of list items
  
      this.collListItem = oList.getItems(camlQuery);
  
      //load the list items into context 
  
      clientContext.load(collListItem);
  
  
      //execute the query 
  
      clientContext.executeQueryAsync(
  
  
  
      Function.createDelegate(this, this.onQuerySucceeded),
  
  
  
      Function.createDelegate(this, this.onQueryFailed)
  
  
  
      );
  
   clientContext.dispose();
  
  }
  
  
  
  function onQuerySucceeded(sender, args) {
  
      // Might be worth starting with this here just to ensure the div is always clear before we start.
  
      $sr("#divListItems").html('');
  
  
      var listItemInfo = '';
  
  
      var listItemEnumerator = this.collListItem.getEnumerator();
  
      //Iterate results
  
  
      while (listItemEnumerator.moveNext()) {
  
          // get the current looped item
  
          var oListItem = listItemEnumerator.get_current();
  
  
          // get the userID from the lookup field
  
          var t = oListItem.get_item('ContactFullName').get_lookupId();
          var u = oListItem.get_item('ContactJobTitleFT');
          var v = oListItem.get_item('ContactRegion');
  
  
          // pass it into the get email method 
  
          getEmail(t,u, v, function(returnedValue) {
  
              //console.log(returnedValue[0])
  
              $sr("#divListItems").append(
  
  
  
                      returnedValue[0]  + 
  
                      //oListItem.get_item('ElementContactFullName').get_lookupValue() +
  
                     // ' &lt;strong&gt;JobTitle:&lt;/strong&gt; ' + oListItem.get_item('ElementContactJobTitle').get_lookupValue() +
  
  
                      '&lt;br /&gt;');
  });
  
      }
  
  
  
  
      // display data
  
      $sr("#divListItems").html(listItemInfo);
  
  
  }
  
  
  
  function onQueryFailed(sender, args) {
  
  
  
      alert('Request failed. ' + args.get_message() +
  
  
  
      '\n' + args.get_stackTrace());
  
  
  }
  
  
  
   function getEmail(userId, JT,  flag, callback) {
  
  
  
      var x = [];
  
      var context = new SP.ClientContext();
  
      var web = context.get_web();
  
      var user = web.get_siteUsers().getById(userId);
  
      context.load(user);
  
  
  
      context.executeQueryAsync(function() {
  
          //console.log(user.get_email());
  
          var y =   "&lt;body&gt;&lt;div class='tablewrapper'&gt;" +
        "&lt;div class='table'&gt;" +
          "&lt;div class='row'&gt;" +
            "&lt;div class='rowspanned cell'&gt;" +
               ' &lt;img class="contacts" src="' + _spPageContextInfo.webServerRelativeUrl + '/_layouts/15/userphoto.aspx?size=M&amp;accountname='+ user.get_email()  +'"/&gt;' +
            "&lt;/div&gt;" +
            "&lt;div class='cell'&gt;" +
             user.get_title() +
            "&lt;/div&gt;" +
          "&lt;/div&gt;" +
          "&lt;div class='row'&gt;" +
            "&lt;div class='empty cell'&gt;&lt;/div&gt;" +
            "&lt;div class='cell'&gt;" +
              JT +  
            "&lt;div class='cell'&gt;" +
           '&lt;img class="flag" src="' + window.location.protocol + "//" + window.location.host   + '/SiteAssets/Images/'+ flag  +'.png"/&gt;' +
           //http://staging.intranet.ent.sys.element.com/SiteAssets/Images/EU.png
            "&lt;/div&gt;" +
          "&lt;/div&gt;" +
          "&lt;/div&gt;" +
        "&lt;/div&gt;" +
      "&lt;/div&gt;"
  
  
          x.push(y);
  
          callback(x);
  
  
  
      }
  
      , function() {
  
          console.log("error");
  
      });
  context.dispose();
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>To reiterate, why wont these run together in seperate CEWPs on a SharePoint page?</p>