0

Using JSOM how can get the URL like the powershell script below using the site GUID

$web = get-spweb -Site 87d28faf-a0ac-4ac6-80a1-96aca53d07b7
$web.Url

Thank you.

0

Here is a JSOM Code snippet to get all sites url based on a web application:

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(loadWebs, "sp.js");
function loadWebs() {
    enumWebs(['Url'],function(webs){
        for(var i = 0; i < webs.length;i++){
        //console.log(webs[i].get_url());
            $("#AllWebUrls").append("<p>"+webs[i].get_url()+"</p>");
        }
    },
    function(sender,args){
        console.log(args.get_message());
    });
}
function enumWebs(propertiesToRetrieve, success,error){
   var ctx = SP.ClientContext.get_current();
   var rootWeb = ctx.get_site().get_rootWeb();
   var result = [];
   var level = 0;
   ctx.load(rootWeb,propertiesToRetrieve);
   result.push(rootWeb);
   var colPropertiesToRetrieve = String.format('Include({0})',propertiesToRetrieve.join(',')); 
   var enumWebsInner = function(web,result,success,error){
      level++;
      var ctx = web.get_context();
      var webs = web.get_webs(); 
      ctx.load(webs,colPropertiesToRetrieve);
      ctx.executeQueryAsync(
        function(){
            for(var i = 0; i < webs.get_count();i++){
                var web = webs.getItemAtIndex(i);
                result.push(web);
                enumWebsInner(web,result,success,error);
            }
            level--;
            if (level == 0 && success)
              success(result);  
        },
        error);
   };
   enumWebsInner(rootWeb,result,success,error);    
}
</script>
<div id="AllWebUrls"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.