Quantcast
Channel: Developing Apps for SharePoint 2013 forum
Viewing all articles
Browse latest Browse all 8089

Loading .js files

$
0
0

Hi guys,

since I am quite new to Javascript development with SharePoint I have some questions to include .js files in my code. 

Before I start: I'm not directly developing an app/add-in for SharePoint. Instead I upload some .js files and a html file in a doc library and include the .html file as a content editor web part in SharePoint to access the .js files (e.g. for some JSOM commands).

In my first program I only needed the sp.js file since I only wanted to retrieve some ListInformations. For that I used the SP.SOD.executefunc command.

In my second program I need some of the TaxonomyValues (a specific termset of the site). Now I am a little bit irritated what I have to load and how to do it. 

If I am right I first have to register the .js files with the SP.SOD.registerSod function, right?
And then I have to load them with SP.SOD.executefunc? Can I load more than one .js file with a single executefunc command?

I also read that you can load .js files with "LoadSodByKey" and "SP.SOD.loadMultiple".

Regardless of which way I choose, my second program doesn't work. You can see the code below. My console says "Cannot read TaxonomySession of undefined". So I assume there is a mistake in loading the .js files? Maybe someone can help me to understand the problem :-)

<html><head><script type="text/javascript" src="jquery.js"></script> ><script
    type="text/javascript"
    src="sp.runtime.js"></script><script
    type="text/javascript"
    src="sp.js"></script><script
    type="text/javascript"
    src="init.js"></script><script
    type="text/javascript"
    src="sp.taxonomy.js"></script><script>
function scriptLoad(){
   SP.SOD.registerSod('sp.taxonomy.js','https://mycompany.sharepoint.com/sites/Tesst/DokuTest/sp.taxonomy.js');
   LoadSodByKey("sp.taxonomy.js", Zugriff());
   SP.SOD.loadMultiple(['sp.runtime.js','sp.js','sp.taxonomy.js'],Zugriff());
}


function Zugriff (){
 var context = new SP.ClientContext('https://abb.sharepoint.com/sites/Tesst');
 var session = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
 var termStores = session.get_termStores();
 context.load(session);
 context.load(termStores);
  context.executeQueryAsync(
 function(){
  var termStoresEnum = termStores.getEnumerator();
  var termStores = "TermStores: /n";
  while (termStoresEnum.moveNext()){
   var currentTermStore = termStoresEnum.get_current();
   var termStoreID = currentTermStore.get_id();
   var termStoreName = currentTermStore.get_name();
   termStores += "Name: " + termStoreName+ " ID:" + termStoreID;
   alert (termStores);
   }
  }, function(){
  //failure loading termstores
  });
}</script><title></title></head><body><input type="button" name="clickme" value="Absenden" onclick="scriptLoad();"></body></html>

Best regards,

André


Viewing all articles
Browse latest Browse all 8089

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>