cancel
Showing results for 
Search instead for 
Did you mean: 

Sites root-scoped javascript variable not defined.

vamirr
Champ on-the-rise
Champ on-the-rise
Greetings,

I'm attempting to modify the Share footer webscript to include some information found in an aspect applied to each site.


The javascript API docs show that there is a root scoped variable 'sites' that gives access to the sites service.   My code below fails on the use of that root scoped variable with the error that it is not defined.

Any thoughts on what I'm missing?    Why is sites undefined when it's supposed to be a root scoped variable? How else should I be getting the site's scriptNode from its shortName?

function main(){
        profile = context.properties["site-profile"]

        if(profile){
                mySite = sites.getSite(profile.shortName);    //fails here…
                mySiteNode = mySite.node;

                if(mySiteNode){
                        if(mySiteNode.hasAspect("ac:siteProps")){
                                model.siteSponsor = mySiteNode.properties["ac:sponsor"];
                        }
                        else{
                                //aspect not applied.
                        }
                }
        }
}
main();
6 REPLIES 6

mikeh
Star Contributor
Star Contributor
It's because the "sites" root object is only present on the Repository tier (/alfresco) and not the Web tier (/share). Share is a remote webapp that communicates with the Repository via JSON-based REST APIs.

You'll need to build a webscript on the repo tier to return the information you need. You can use the remote.call() function in the footer's JavaScript controller to make the call. Look throughout the Share source code for many examples of this pattern.

Thanks,
Mike

vamirr
Champ on-the-rise
Champ on-the-rise
Understood.  Thank you.

vamirr
Champ on-the-rise
Champ on-the-rise
Mike,  I seem to be getting the same thing on the alfresco side:

Message:   07240016 Wrapped Exception (with status template): 07240040 Failed to execute script '/org/aeroCOMPASS/getSiteProps.get.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions)': 07240039 ReferenceError: "sites" is not defined. (workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions/org/aeroCOMPASS/getSiteProps.get.js#4)
   
Exception:   org.mozilla.javascript.EcmaError - ReferenceError: "sites" is not defined. (workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions/org/aeroCOMPASS/getSiteProps.get.js#4)

var sitename = url.templateArgs["shortName"];

if(sitename){
   mySite = sites.getSite(sitename);
   mySiteNode = mySite.node;

   if(mySiteNode){
      if(mySiteNode.hasAspect("ac:siteOwner")){
         model.siteOwner = mySiteNode.properties["ac:sponsor"];
         model.siteSponsor = mySiteNode.properties["ac:sponsor"];
      }
   }
   else{
      
      }
}

mikeh
Star Contributor
Star Contributor
Ah sorry -didn't spot you were using "sites" - try "siteService"

Thanks,
Mike

jevon
Champ in-the-making
Champ in-the-making

mikeh
Star Contributor
Star Contributor
No, it's just that those only apply on the Repository tier. I admit that's not particular clear from those pages. Please do feel free to edit them if you think that needs clarifying.

Thanks,
Mike